home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap06 / howto01 / delphi10 / drwsutl4.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-04  |  128.7 KB  |  3,506 lines

  1. unit Drwsutl4;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22.  
  23.   KBMJ_SINGLE = 1;   { Keyboard mouse motion constant for single pixel moves }
  24.   KBMJ_SMALL = 10;    { Keyboard mouse motion constant for single pixel moves }
  25.   KBMJ_LARGE = 50;    { Keyboard mouse motion constant for single pixel moves }
  26.  
  27.   CR_KEYSET = 6; { ID for special keypress cursor }
  28.   CR_NULL = 7;   { ID for Null (blank) cursor     }
  29. type
  30.   { This is a descendant of TFileListbox }
  31.   { Which puts icons of files into the   }
  32.   { Objects array rather than the stand- }
  33.   { ard bitmaps.                         }
  34.   TIconFileListBox = class( TFileListBox )
  35.   public
  36.     { public methods and data }
  37.     procedure ReadFileNames; override;
  38.     function GetNextSelection( SourceDirectory : String;
  39.               var CurrentItem : Integer ) : String;
  40.     constructor Create(AOwner : TComponent); override; { override create    }
  41.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  42.   end;
  43.   TFileWorkBench = class( TComponent )
  44.   public
  45.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  46.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  47.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  48.     function StripNonRootTrailingBackSlash(
  49.               const TheFileName : String ) : String;
  50.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  51.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  52.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  53.                                  TheMessage : String; TheCode : Integer );
  54.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  55.                 TheCode : Integer );
  56.     function CopyFile( TargetPath ,
  57.                DestinationPath : String ) : Boolean;
  58.     procedure ChangeTheDirectory( NewPath : String );
  59.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  60.     procedure CopyTheFile( OldPath , NewPath : String );
  61.     procedure MoveTheFile( OldPath , NewPath : String );
  62.     procedure DeleteTheFile( ThePath : String );
  63.     procedure RenameTheFile( OldPath , NewName : String );
  64.     procedure CreateNewDirectory( NewPath : String );
  65.     procedure RemoveDirectory( ThePath : String );
  66.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  67.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  68.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  69.     procedure RecursivelyDeleteDirectory( ThePath : String );
  70.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  71.                ActionCode : Integer );
  72.   end;
  73.   TFileIconPanel = class( TPanel )
  74.   private
  75.     { Private declarations }
  76.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  77.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  78.     procedure TheMouseDown(Sender: TObject;
  79.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80.     procedure TheMouseMove( Sender: TObject; Shift: TShiftState;
  81.       X, Y: Integer);
  82.     procedure TheMouseUp(Sender: TObject;
  83.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  84.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  85.      message WM_LBUTTONDBLCLK;
  86.     procedure TheDragOver(Sender, Source: TObject; X,
  87.       Y: Integer; State: TDragState; var Accept: Boolean);
  88.     procedure TheDragDrop(Sender, Source: TObject; X,
  89.       Y: Integer);
  90.   protected                                   { event method procedure.      }
  91.     { Protected declarations }
  92.     procedure Paint; override;                { This allows custom painting  }
  93.   public
  94.     { Public declarations }
  95.     FTheIcon : TIcon;                         { This is the display icon    }
  96.     FTheBMP  : TBitmap;                       { This holds a thumbnail image}
  97.     FTheName : String;                        { This is the filename        }
  98.     FTheLabel : TLabel;                       { This is the display label   }
  99.     Selected : Boolean;                       { This holds selection status }
  100.     constructor Create(AOwner : TComponent); override; { override create    }
  101.     procedure Initialize( PanelX              ,             { Left          }
  102.                           PanelY              ,             { Top           }
  103.                           PanelWidth          ,             { Width         }
  104.                           PanelHeight         ,             { Height        }
  105.                           PanelBevelWidth     ,             { Bevel Width   }
  106.                           LabelFontSize         : Integer;  { Font size     }
  107.                           PanelColor          ,             { Main color    }
  108.                           PanelHighlightColor ,             { Bright color  }
  109.                           PanelShadowColor    ,             { Dark color    }
  110.                           LabelTextColor        : TColor;   { Text color    }
  111.                           TheFilename         ,             { Filename      }
  112.                           LabelFontName         : String;   { Font name     }
  113.                           LabelFontStyle        : TFontStyles;  { Font style}
  114.                           ExtraData             : Integer       );  { Drive }
  115.     destructor Destroy; override;             { override destroy to free    }
  116.   end;
  117.   TFileIconPanelScrollBox = class( TScrollBox )
  118.   public
  119.     { Public methods and data }
  120.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  121.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  122.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  123.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  124.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  125.     TheStoredHandle    : HWnd;
  126.     TheParentForm      : TForm;
  127.     procedure Update;                                { Called to reset display }
  128.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  129.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  130.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  131.     procedure GetColorsForFileIcon( TheFile : String;
  132.                var BC , HC , SC , TC : TColor );
  133.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  134.     function GetNextSelection( SourceDirectory : String;
  135.               var CurrentItem : Integer ) : String;
  136.     procedure DisplayRecursiveSearchResults(
  137.       TheStartingDirectory : String );
  138.   end;
  139.   TIOManager = class( TComponent )
  140.   public
  141.     Parent : TForm;
  142.     WhichButton : TMouseButton;
  143.     WhichState  : TShiftState;
  144.     CLState ,
  145.     NLState ,
  146.     SLState   : Boolean;
  147.     function IsCapsLockDown : Boolean;
  148.     function ISNumLockDown : Boolean;
  149.     function IsScrollLockDown : Boolean;
  150.     procedure InitLocks;
  151.     procedure ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  152.     procedure SetLocks( TheCL , TheNL , TheSL : Boolean );
  153.     function WasLeftPressed : Boolean;
  154.     function WasRightPressed : Boolean;
  155.     function WasMiddlePressed : Boolean;
  156.     function WasALTPressed : Boolean;
  157.     function WasSHIFTPressed : Boolean;
  158.     function WasCTRLPressed : Boolean;
  159.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  160.      Shift: TShiftState);
  161.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  162.      Shift: TShiftState);
  163.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  164.      Shift: TShiftState);
  165.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  166.      Shift: TShiftState);
  167.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  168.      Shift: TShiftState);
  169.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  170.      Shift: TShiftState);
  171.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  172.      Shift: TShiftState);
  173.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  174.      Shift: TShiftState);
  175.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  176.      Shift: TShiftState);
  177.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  178.      Shift: TShiftState);
  179.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  180.      Shift: TShiftState);
  181.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  182.      Shift: TShiftState);
  183.  end;
  184.  TMouseManager = class( TComponent )
  185.  public
  186.    TheMX : Integer;
  187.    TheMY : Integer;
  188.    Old_X ,
  189.    Old_Y ,
  190.    New_X ,
  191.    New_Y   : Integer;
  192.    StoredCursor : Integer;
  193.    BitmapCursor  : Boolean;
  194.    IconCursor    : Boolean;
  195.    CursorBMP     : TBitmap;
  196.    CursorIcon    : TIcon;
  197.    IsAnimated    : Boolean;
  198.    TheTimer      : TTimer;
  199.    TheAnimationList : TList;
  200.    CurrentAnimationPointer : Integer;
  201.    AnimationInterval : Integer;
  202.    SavedDC ,
  203.    GlobalDC : HDC;
  204.    GlobalCanvas : TCanvas;
  205.    WorkSpaceBMP : TBitmap;
  206.    BackGroundBMP : TBitmap;
  207.    constructor Create( AOwner : TComponent ); override;
  208.    destructor Destroy; override;
  209.    procedure InitializeNormal;
  210.    procedure InitializeBitmap( TheBmp : TBitmap );
  211.    procedure InitializeIcon( TheIcon : TIcon );
  212.    procedure InitializeAnimated( TheIcon : TIcon; TheInterval : Integer;
  213.                                  TheIconList : TList );
  214.    procedure GetMousePosition( var MouseX , MouseY : Integer );
  215.    procedure SetMousePosition( MouseX , MouseY : Integer );
  216.    procedure MoveSinglePixelLeft;
  217.    procedure MoveSinglePixelRight;
  218.    procedure MoveSinglePixelUp;
  219.    procedure MoveSinglePixelDown;
  220.    procedure MoveSmallJumpLeft;
  221.    procedure MoveSmallJumpRight;
  222.    procedure MoveSmallJumpUp;
  223.    procedure MoveSmallJumpDown;
  224.    procedure MoveLargeJumpLeft;
  225.    procedure MoveLargeJumpRight;
  226.    procedure MoveLargeJumpUp;
  227.    procedure MoveLargeJumpDown;
  228.    procedure StartBitmapCursor( TheX , TheY : Integer );
  229.    procedure MoveBitmapCursor( TheX , TheY : Integer );
  230.    procedure EndBitmapCursor( TheX , TheY : Integer );
  231.    procedure StartIconCursor( TheX , TheY : Integer );
  232.    procedure MoveIconCursor( TheX , TheY : Integer );
  233.    procedure EndIconCursor( TheX , TheY : Integer );
  234.    procedure StartAnimatedIconCursor( TheX , TheY : Integer );
  235.    procedure EndAnimatedIconCursor( TheX , TheY : Integer );
  236.    procedure MoveAnimatedIconCursor( TheX , TheY : Integer );
  237.    procedure TimerAction( Sender : TObject );
  238.  end;
  239.  
  240.   { This procedure gets an icon for a file using FindExecutable  }
  241.   { and ExtractIcon. (assumes file/dir is passed)                }
  242.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  243.   { This procedure spaces out the bitbtn components on a tpanel }
  244.   procedure SpacePanelButtons( WhichPanel : TPanel );
  245.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  246.                GlobalErrorCode : Integer );
  247.  
  248. var TheIOManager : TIOManager;
  249.     TheMouseManager : TMouseManager;
  250.     GlobalAbortFlag : Boolean;
  251.     SavedForm : TForm;
  252.     SavedControl : TFileIconPanel;
  253.     OtherSavedControl : TFileIconPanelScrollbox;
  254.     Savedhandle : HWnd;
  255.     IconDragging : boolean;
  256.     GlobalSource : TObject;
  257.     TheTempBitmap : TBitmap;
  258.     BitmapDragging : boolean;
  259.     ThumbNailWidth,
  260.     ThumbNailHeight : Integer;
  261.  
  262. implementation
  263. {$R DRWSUTL4.RES}                 { Import custom resource file }
  264. uses UFMGR30,DRWSUtl6;
  265.  
  266. { It has been edited to return viable error codes!             }
  267. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  268.             GlobalErrorCode : Integer );
  269. var
  270.   CopyBuffer: Pointer; { buffer for copying }
  271.   BytesCopied: Longint;
  272.   TheAttr : Integer;
  273.   Source, Dest: Integer; { handles }
  274. const
  275.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  276. begin
  277.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  278.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  279.   if Source < 0 then
  280.   begin  { error creating source file }
  281.     GlobalErrorType := EOC_SOURCECOPY;
  282.     GlobalErrorCode := -IOResult;
  283.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  284.     FreeMem( CopyBuffer, ChunkSize );
  285.     exit;
  286.   end;
  287.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  288.   if Dest < 0 then
  289.   begin  { error creating destination file }
  290.     FileClose( Source );
  291.     GlobalErrorType := EOC_DESTCOPY;
  292.     GlobalErrorCode := -IOResult;
  293.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  294.     FreeMem( CopyBuffer , ChunkSize );
  295.     exit;
  296.   end;
  297.   {$I-}
  298.   repeat
  299.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  300.     if BytesCopied > 0 then { if we read anything... }
  301.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  302.   until BytesCopied < ChunkSize; { until we run out of chunks }
  303.   {$I+}
  304.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  305.   FileClose(Dest); { close the destination file }
  306.   FileClose(Source); { close the source file }
  307.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  308. end;
  309.  
  310. { This procedure spaces out the bitbtn components on a tpanel }
  311. procedure SpacePanelButtons( WhichPanel : TPanel );
  312. var TheCalculatedSpacing     ,            { Holds primary spacing }
  313.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  314.     Counter_1                  : Integer; { Loop counter          }
  315.     TotalIBs                   : Integer; { Gets total buttons    }
  316. begin
  317.   { Set up spacing values }
  318.   TotalIBs := WhichPanel.ControlCount;
  319.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  320.    div ( TotalIbs + 1 ));
  321.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  322.   { Loop through all imported buttons and set their Left values }
  323.   for Counter_1 := 1 to WhichPanel.ControlCount do
  324.   begin
  325.     if Counter_1 = 1 then
  326.     begin
  327.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  328.        TheCalculatedSpacing;
  329.     end
  330.     else
  331.     begin
  332.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  333.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  334.     end;
  335.   end;
  336. end;
  337.  
  338. { This procedure gets an icon for a file using FindExecutable  }
  339. { and ExtractIcon. (assumes file/dir is passed)                }
  340. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  341. var TheExt           : String; { File extension holder }
  342.     TheOtherPChar  ,           { Windows ASCIIZ string }
  343.     TheResultPChar ,           { Windows ASCIIZ string }
  344.     ThePChar         : PChar;  { Windows ASCIIZ string }
  345. begin
  346.   { Check for directory and if so get directory icon from RES file }
  347.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  348.   begin
  349.     { Set up the PChar to communicate with Windows }
  350.     GetMem( TheOtherPChar , 255 );
  351.     { Convert Pascal-style string to ASCIIZ Pchar }
  352.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  353.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  354.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  355.     { Release memory from PChar }
  356.     FreeMem( TheOtherPChar , 255 );
  357.     { Leave }
  358.     exit;
  359.   end;
  360.   { Assume archive file; get its extension }
  361.   TheExt := Uppercase( ExtractFileExt( TheName ));
  362.   { If not an executable/image file then use FindExecutable to get icon }
  363.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  364.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  365.   begin
  366.     { Grab three chunks of memory }
  367.     GetMem( TheOtherPChar , 255 );
  368.     GetMem( TheResultPChar , 255 );
  369.     GetMem( ThePChar , 255 );
  370.     { Set up the name and its directory in Windows string formats }
  371.     StrPCopy( ThePChar, TheName );
  372.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  373.     { Use FindExecutable API call to get path and name of owning file }
  374.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  375.     begin
  376.       { If get a result of 32 or more then try to get first icon of owner }
  377.       { Using ExtractIcon API call; 0 indicates first icon.               }
  378.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  379.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  380.       if TheIcon.Handle = 0 then
  381.       begin
  382.         GetMem( TheOtherPChar , 255 );
  383.         StrPCopy( TheOtherPChar , 'NOICON' );
  384.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  385.         FreeMem( TheOtherPChar , 255 );
  386.         exit;
  387.       end;
  388.     end
  389.     else
  390.     { if no assigned executable, then get default icon from RES file }
  391.     begin
  392.       GetMem( TheOtherPChar , 255 );
  393.       StrPCopy( TheOtherPChar , 'NOICON' );
  394.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  395.       FreeMem( TheOtherPChar , 255 );
  396.       exit;
  397.     end;
  398.     FreeMem( TheOtherPChar , 255 );
  399.     FreeMem( TheResultPChar , 255 );
  400.     FreeMem( ThePChar , 255 );
  401.   end
  402.   else
  403.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  404.   begin
  405.     GetMem( ThePChar , 255 );
  406.     StrPCopy( ThePChar , TheName );
  407.     { If no icons in file then get default icon (note use FFFF for -1) }
  408.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  409.     begin
  410.       Freemem( ThePChar , 255 );
  411.       GetMem( TheOtherPChar , 255 );
  412.       StrPCopy( TheOtherPChar , 'NOICON' );
  413.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  414.       FreeMem( TheOtherPChar , 255 );
  415.       exit;
  416.     end
  417.     else
  418.     begin
  419.       { Try to get first icon for file }
  420.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  421.       FreeMem( ThePChar , 255 );
  422.       { If handle is 0 invalid icon format so use default from RES file }
  423.       if TheIcon.Handle = 0 then
  424.       begin
  425.         GetMem( TheOtherPChar , 255 );
  426.         StrPCopy( TheOtherPChar , 'NOICON' );
  427.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  428.         FreeMem( TheOtherPChar , 255 );
  429.         exit;
  430.       end;
  431.     end;
  432.   end;
  433. end;
  434.  
  435. { This creates the TMouseManager and inits vars to null }
  436. constructor TMouseManager.Create( AOwner : TComponent );
  437. begin
  438.   { Call inherited FIRST! }
  439.   inherited Create( AOwner );
  440.   { Set all variables to 0 , false or nil }
  441.   TheMX := 0;
  442.   TheMY := 0;
  443.   Old_X  := 0;
  444.   Old_Y  := 0;
  445.   New_X  := 0;
  446.   New_Y  := 0;
  447.   StoredCursor := 0;
  448.   BitmapCursor  := false;
  449.   IconCursor    := false;
  450.   CursorBMP     := nil;
  451.   CursorIcon    := nil;
  452.   IsAnimated    := false;
  453.   TheTimer      := nil;
  454.   TheAnimationList := nil;
  455.   CurrentAnimationPointer := 0;
  456.   AnimationInterval := 0;
  457.   SavedDC := 0;
  458.   GlobalDC := 0;
  459.   GlobalCanvas := nil;
  460.   WorkSpaceBMP := nil;
  461.   BackGroundBMP := nil;
  462. end;
  463.  
  464. { This destroys the tmousemanager and releases all resources }
  465. destructor TMouseManager.Destroy;
  466. begin
  467.   { Free any assigned resources (the moving bmp ones already are gone) }
  468.   if assigned( TheTimer ) then
  469.    TheTimer.Free;
  470.   if assigned( TheAnimationList ) then
  471.    TheAnimationList.Free;
  472.   Inherited Destroy;
  473. end;
  474.  
  475. { This sets up the mouse manager for normal cursor operations }
  476. procedure TMouseManager.InitializeNormal;
  477. var TheMP : TPoint;
  478. begin
  479.   { Reset State Variables }
  480.   BitmapCursor := false;
  481.   IconCursor := false;
  482.   IsAnimated := false;
  483.   { Call API to get mouse coordinates }
  484.   GetCursorPos( TheMP );
  485.   { Store the coordinates for later use }
  486.   TheMX := TheMP.X;
  487.   TheMY := TheMP.Y;
  488.   Old_X := TheMX;
  489.   Old_Y := TheMY;
  490.   New_X := TheMX;
  491.   New_Y := TheMY;
  492. end;
  493.  
  494. { This procedure initializes a bitmap cursor }
  495. procedure TMouseManager.InitializeBitmap( TheBmp : TBitmap );
  496. begin
  497.   InitializeNormal;
  498.   CursorBMP := TheBMP;
  499.   BitmapCursor := true;
  500. end;
  501.  
  502. { This procedure initalizes an icon cursor }
  503. procedure TMouseManager.InitializeIcon( TheIcon : TIcon );
  504. begin
  505.   InitializeNormal;
  506.   CursorIcon := TheIcon;
  507.   IconCursor := true;
  508. end;
  509.  
  510. { This procedure initializes an animated icon cursor }
  511. procedure TMouseManager.InitializeAnimated( TheIcon : TIcon;
  512.            TheInterval : Integer; TheIconList : TList );
  513. begin
  514.   InitializeNormal;
  515.   CursorIcon := TheIcon;
  516.   IconCursor := true;
  517.   IsAnimated := true;
  518.   AnimationInterval := TheInterval;
  519.   TheAnimationList := TheIconList;
  520.   TheTimer := TTimer.Create( Self );
  521.   TheTimer.Enabled := false;
  522.   TheTimer.Interval := AnimationInterval;
  523.   TheTimer.OnTimer := TimerAction;
  524. end;
  525.  
  526. { This procedure returns the current stored mouse position }
  527. procedure TMouseManager.GetMousePosition( var MouseX , MouseY : Integer );
  528. begin
  529.   { Return stored position rather than call API }
  530.   MouseX := TheMX;
  531.   MouseY := TheMY;
  532. end;
  533.  
  534. { This procedure sets the Mouse Position internally }
  535. procedure TMouseManager.SetMousePosition( MouseX , MouseY : Integer );
  536. begin
  537.   { Set internal coordinates; don't call API }
  538.   TheMX := MouseX;
  539.   TheMY := MouseY;
  540. end;
  541.  
  542. { This procedure is used to drive the mouse with the keyboard }
  543. procedure TMouseManager.MoveSinglePixelLeft;
  544. begin
  545.   { Use internal coordinates and check for screen wrapping }
  546.   if TheMX > KBMJ_SINGLE then
  547.   begin
  548.     { Not wrapped; move along one unit to the left }
  549.     TheMX := TheMX - KBMJ_SINGLE;
  550.     SetCursorPos( TheMX , TheMY );
  551.   end
  552.   else
  553.   begin
  554.     { Wrapped; jump to right and move back one unit }
  555.     TheMX := Screen.Width - KBMJ_SINGLE;
  556.     SetCursorPos( TheMX , TheMY );
  557.   end;
  558. end;
  559.  
  560. { This procedure is used to drive the mouse with the keyboard }
  561. procedure TMouseManager.MoveSinglePixelRight;
  562. begin
  563.   { Use internal coordinates and check for screen wrapping }
  564.   if TheMX < ( Screen.Width - KBMJ_SINGLE ) then
  565.   begin
  566.     { Not wrapped; move along one unit to the right }
  567.     TheMX := TheMX + KBMJ_SINGLE;
  568.     SetCursorPos( TheMX , TheMY );
  569.   end
  570.   else
  571.   begin
  572.     { Wrapped; jump to left and move in one unit }
  573.     TheMX := KBMJ_SINGLE;
  574.     SetCursorPos( TheMX , TheMY );
  575.   end;
  576. end;
  577.  
  578. { This procedure is used to drive the mouse with the keyboard }
  579. procedure TMouseManager.MoveSinglePixelUp;
  580. begin
  581.   { Use internal coordinates and check for screen wrapping }
  582.   if TheMY > KBMJ_SINGLE then
  583.   begin
  584.     { Not wrapped; move along one unit to the top }
  585.     TheMY := TheMY - KBMJ_SINGLE;
  586.     SetCursorPos( TheMX , TheMY );
  587.   end
  588.   else
  589.   begin
  590.     { Wrapped; jump to bottom and move back one unit }
  591.     TheMY := Screen.Height - KBMJ_SINGLE;
  592.     SetCursorPos( TheMX , TheMY );
  593.   end;
  594. end;
  595.  
  596. { This procedure is used to drive the mouse with the keyboard }
  597. procedure TMouseManager.MoveSinglePixelDown;
  598. begin
  599.   { Use internal coordinates and check for screen wrapping }
  600.   if TheMY < ( Screen.Height - KBMJ_SINGLE ) then
  601.   begin
  602.     { Not wrapped; move along one unit to the bottom }
  603.     TheMY := TheMY + KBMJ_SINGLE;
  604.     SetCursorPos( TheMX , TheMY );
  605.   end
  606.   else
  607.   begin
  608.     { Wrapped; jump to top and move back one unit }
  609.     TheMY := KBMJ_SINGLE;
  610.     SetCursorPos( TheMX , TheMY );
  611.   end;
  612. end;
  613.  
  614. { This procedure is used to drive the mouse with the keyboard }
  615. procedure TMouseManager.MoveSmallJumpLeft;
  616. begin
  617.   { Use internal coordinates and check for screen wrapping }
  618.   if TheMX > KBMJ_SMALL then
  619.   begin
  620.     { Not wrapped; move along one unit to the left }
  621.     TheMX := TheMX - KBMJ_SMALL;
  622.     SetCursorPos( TheMX , TheMY );
  623.   end
  624.   else
  625.   begin
  626.     { Wrapped; jump to right and move back the unit }
  627.     TheMX := Screen.Width - KBMJ_SMALL;
  628.     SetCursorPos( TheMX , TheMY );
  629.   end;
  630. end;
  631.  
  632. { This procedure is used to drive the mouse with the keyboard }
  633. procedure TMouseManager.MoveSmallJumpRight;
  634. begin
  635.   { Use internal coordinates and check for screen wrapping }
  636.   if TheMX < ( Screen.Width - KBMJ_SMALL ) then
  637.   begin
  638.     { Not wrapped; move along one unit to the right }
  639.     TheMX := TheMX + KBMJ_SMALL;
  640.     SetCursorPos( TheMX , TheMY );
  641.   end
  642.   else
  643.   begin
  644.     { Wrapped; jump to left and move in one unit }
  645.     TheMX := KBMJ_SMALL;
  646.     SetCursorPos( TheMX , TheMY );
  647.   end;
  648. end;
  649.  
  650. { This procedure is used to drive the mouse with the keyboard }
  651. procedure TMouseManager.MoveSmallJumpUp;
  652. begin
  653.   { Use internal coordinates and check for screen wrapping }
  654.   if TheMY > KBMJ_SMALL then
  655.   begin
  656.     { Not wrapped; move along one unit to the top }
  657.     TheMY := TheMY - KBMJ_SMALL;
  658.     SetCursorPos( TheMX , TheMY );
  659.   end
  660.   else
  661.   begin
  662.     { Wrapped; jump to bottom and move back one unit }
  663.     TheMY := Screen.Height - KBMJ_SMALL;
  664.     SetCursorPos( TheMX , TheMY );
  665.   end;
  666. end;
  667.  
  668. { This procedure is used to drive the mouse with the keyboard }
  669. procedure TMouseManager.MoveSmallJumpDown;
  670. begin
  671.   { Use internal coordinates and check for screen wrapping }
  672.   if TheMY < ( Screen.Height - KBMJ_SMALL ) then
  673.   begin
  674.     { Not wrapped; move along one unit to the bottom }
  675.     TheMY := TheMY + KBMJ_SMALL;
  676.     SetCursorPos( TheMX , TheMY );
  677.   end
  678.   else
  679.   begin
  680.     { Wrapped; jump to top and move back one unit }
  681.     TheMY := KBMJ_SMALL;
  682.     SetCursorPos( TheMX , TheMY );
  683.   end;
  684. end;
  685.  
  686. { This procedure is used to drive the mouse with the keyboard }
  687. procedure TMouseManager.MoveLargeJumpLeft;
  688. begin
  689.   { Use internal coordinates and check for screen wrapping }
  690.   if TheMX > KBMJ_LARGE then
  691.   begin
  692.     { Not wrapped; move along the unit to the left }
  693.     TheMX := TheMX - KBMJ_LARGE;
  694.     SetCursorPos( TheMX , TheMY );
  695.   end
  696.   else
  697.   begin
  698.     { Wrapped; jump to right and move back the unit }
  699.     TheMX := Screen.Width - KBMJ_LARGE;
  700.     SetCursorPos( TheMX , TheMY );
  701.   end;
  702. end;
  703.  
  704. { This procedure is used to drive the mouse with the keyboard }
  705. procedure TMouseManager.MoveLargeJumpRight;
  706. begin
  707.   { Use internal coordinates and check for screen wrapping }
  708.   if TheMX < ( Screen.Width - KBMJ_LARGE ) then
  709.   begin
  710.     { Not wrapped; move along one unit to the right }
  711.     TheMX := TheMX + KBMJ_LARGE;
  712.     SetCursorPos( TheMX , TheMY );
  713.   end
  714.   else
  715.   begin
  716.     { Wrapped; jump to left and move in one unit }
  717.     TheMX := KBMJ_LARGE;
  718.     SetCursorPos( TheMX , TheMY );
  719.   end;
  720. end;
  721.  
  722. { This procedure is used to drive the mouse with the keyboard }
  723. procedure TMouseManager.MoveLargeJumpUp;
  724. begin
  725.   { Use internal coordinates and check for screen wrapping }
  726.   if TheMY > KBMJ_LARGE then
  727.   begin
  728.     { Not wrapped; move along one unit to the top }
  729.     TheMY := TheMY - KBMJ_LARGE;
  730.     SetCursorPos( TheMX , TheMY );
  731.   end
  732.   else
  733.   begin
  734.     { Wrapped; jump to bottom and move back one unit }
  735.     TheMY := Screen.Height - KBMJ_LARGE;
  736.     SetCursorPos( TheMX , TheMY );
  737.   end;
  738. end;
  739.  
  740. { This procedure is used to drive the mouse with the keyboard }
  741. procedure TMouseManager.MoveLargeJumpDown;
  742. begin
  743.   { Use internal coordinates and check for screen wrapping }
  744.   if TheMY < ( Screen.Height - KBMJ_LARGE ) then
  745.   begin
  746.     { Not wrapped; move along one unit to the bottom }
  747.     TheMY := TheMY + KBMJ_LARGE;
  748.     SetCursorPos( TheMX , TheMY );
  749.   end
  750.   else
  751.   begin
  752.     { Wrapped; jump to top and move back one unit }
  753.     TheMY := KBMJ_LARGE;
  754.     SetCursorPos( TheMX , TheMY );
  755.   end;
  756. end;
  757.  
  758. { This procedure sets up the bitmaps and global HDC prior to moving a }
  759. { Bitmap cursor.                                                      }
  760. procedure TMouseManager.StartBitmapCursor( TheX , TheY : Integer );
  761. var WorkingPoint1 ,
  762.     WorkingPoint2 : TPoint;
  763. begin
  764.   GlobalDC := GetDC( 0 );
  765.   WorkspaceBMP := TBitmap.Create;
  766.   WorkspaceBMP.Width := Screen.Width;
  767.   WorkSpaceBMP.Height := Screen.Height;
  768.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  769.    GlobalDC , 0 , 0 , SrcCopy );
  770.   BackgroundBMP := TBitmap.Create;
  771.   BackgroundBMP.Width := CursorBMP.Width;
  772.   BackgroundBMP.Height := CursorBMP.Height;
  773.   New_X := TheX;
  774.   New_Y := TheY;
  775.   StoredCursor := Screen.Cursor;
  776.   Screen.Cursor := CR_NULL;
  777.   {Grab the background image}
  778.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  779.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  780.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  781.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  782.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  783.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  784.     WorkingPoint2.Y ));
  785.   {Put the cursor bitmap onto the workspace canvas}
  786.   with WorkspaceBMP.Canvas do
  787.   begin
  788.     CopyMode := cmSrcCopy;
  789.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  790.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  791.   end;
  792.   {Copy the workspace bitmap onto the visible screen}
  793.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  794.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  795.   Old_X := New_X;
  796.   Old_Y := New_Y;
  797. end;
  798.  
  799. { This procedure moves a bitmap cursor according to the imported New coords }
  800. procedure TMouseManager.MoveBitmapCursor( TheX , TheY : Integer );
  801. var StartX,
  802.     StartY,
  803.     XDiff,
  804.     YDiff : Integer;
  805.     WorkingPoint1 ,
  806.     WorkingPoint2  : TPoint;
  807. begin
  808.   New_X := TheX;
  809.   New_Y := TheY;
  810.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  811.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height div 2 );
  812.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  813.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  814.   with WorkspaceBMP.Canvas do
  815.   begin
  816.     CopyMode := cmSrcCopy;
  817.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  818.       BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  819.   end;
  820.   {Put the saved bitmap onto the workspace canvas}
  821.   with WorkspaceBMP.Canvas do
  822.   begin
  823.     CopyMode := cmSrcCopy;
  824.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  825.      BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  826.   end;
  827.   {Grab the background image}
  828.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  829.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  830.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  831.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  832.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  833.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  834.     WorkingPoint2.Y ));
  835.   {Put the cursor bitmap onto the workspace canvas}
  836.   with WorkspaceBMP.Canvas do
  837.   begin
  838.     CopyMode := cmSrcCopy;
  839.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  840.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  841.   end;
  842.   {Copy the workspace bitmap onto the visible screen}
  843.   if New_X > Old_X then StartX := Old_X else StartX := New_X;
  844.   if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  845.   XDiff := Abs( Old_X - New_X );
  846.   YDiff := Abs( Old_Y - New_Y );
  847.   {Grab the background image}
  848.   WorkingPoint1.X := StartX - ( CursorBMP.Width div 2 );
  849.   WorkingPoint1.Y := StartY - ( CursorBMP.Height div 2 );
  850.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width + XDiff ,
  851.    CursorBMP.Height + YDiff , WorkspaceBMP.Canvas.Handle , WorkingPoint1.X ,
  852.     WorkingPoint1.Y , SrcCopy );
  853.   Old_X := New_X;
  854.   Old_Y := New_Y;
  855. end;
  856.  
  857. { This procedure releases a bitmap cursor and frees its DC }
  858. procedure TMouseManager.EndBitmapCursor( TheX , TheY : Integer );
  859. var WorkingPoint1 ,
  860.     WorkingPoint2 : TPoint;
  861. begin
  862.   BitmapCursor := false;
  863.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  864.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height Div 2 );
  865.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  866.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  867.   {Put the saved bitmap onto the workspace canvas}
  868.   with WorkspaceBMP.Canvas do
  869.   begin
  870.     CopyMode := cmSrcCopy;
  871.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  872.        BackGroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width ,  CursorBMP.Height ));
  873.   end;
  874.   {Copy the workspace bitmap onto the visible screen}
  875.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  876.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  877.   ReleaseDC( 0 , GlobalDC );
  878.   Screen.Cursor := StoredCursor;
  879. end;
  880.  
  881. { This procedure starts the process of displaying an icon cursor }
  882. procedure TMouseManager.StartIconCursor( TheX , TheY : Integer );
  883. var WorkingPoint1 ,
  884.     WorkingPoint2 : TPoint;
  885. begin
  886.   GlobalDC := GetDC( 0 );
  887.   WorkspaceBMP := TBitmap.Create;
  888.   WorkspaceBMP.Width := Screen.Width;
  889.   WorkSpaceBMP.Height := Screen.Height;
  890.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  891.    GlobalDC , 0 , 0 , SrcCopy );
  892.   BackgroundBMP := TBitmap.Create;
  893.   BackgroundBMP.Width := 33;
  894.   BackgroundBMP.Height := 33;
  895.   New_X := TheX;
  896.   New_Y := TheY;
  897.   StoredCursor := Screen.Cursor;
  898.   Screen.Cursor := CR_NULL;
  899.   {Grab the background image}
  900.   WorkingPoint1.X := New_X - 16;
  901.   WorkingPoint1.Y := New_Y - 16;
  902.   WorkingPoint2.X := New_X + 17;
  903.   WorkingPoint2.Y := New_Y + 17;
  904.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  905.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  906.   {Put the icon onto the workspace canvas}
  907.   with WorkspaceBMP.Canvas do
  908.   begin
  909.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  910.   end;
  911.   {Copy the workspace bitmap onto the visible screen}
  912.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  913.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  914.   Old_X := New_X;
  915.   Old_Y := New_Y;
  916. end;
  917.  
  918. { This procedure moves the icon cursor in response to mouse moves }
  919. procedure TMouseManager.MoveIconCursor( TheX , TheY : Integer );
  920. var StartX,
  921.     StartY,
  922.     XDiff,
  923.     YDiff : Integer;
  924.     WorkingPoint1 ,
  925.     WorkingPoint2  : TPoint;
  926. begin
  927.   New_X := TheX;
  928.   New_Y := TheY;
  929.   {Put the saved bitmap onto the workspace canvas}
  930.   WorkingPoint1.X := Old_X - 16;
  931.   WorkingPoint1.Y := Old_Y - 16;
  932.   WorkingPoint2.X := Old_X + 17;
  933.   WorkingPoint2.Y := Old_Y + 17;
  934.   with WorkspaceBMP.Canvas do
  935.   begin
  936.     CopyMode := cmSrcCopy;
  937.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  938.       BackgroundBMP.Canvas , Rect( 0 , 0 , 33 , 33 ));
  939.   end;
  940.   {Grab the background image}
  941.   WorkingPoint1.X := New_X - 16;
  942.   WorkingPoint1.Y := New_Y - 16;
  943.   WorkingPoint2.X := New_X + 17;
  944.   WorkingPoint2.Y := New_Y + 17;
  945.   BackgroundBMP.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  946.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  947.   {Put the icon onto the workspace canvas}
  948.   with WorkspaceBMP.Canvas do
  949.   begin
  950.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  951.   end;
  952.   {Copy the workspace bitmap onto the visible screen}
  953.     if New_X > Old_X then StartX := Old_X else StartX := New_X;
  954.     if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  955.     XDiff := Abs( Old_X - New_X );
  956.     YDiff := Abs( Old_Y - New_Y );
  957.     {Grab the background image}
  958.     WorkingPoint1.X := StartX - 16;
  959.     WorkingPoint1.Y := StartY - 16;
  960.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 + XDiff , 33 + YDiff ,
  961.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  962.   Old_X := New_X;
  963.   Old_Y := New_Y;
  964. end;
  965.  
  966. { This procedure ends the icon cursor movement and frees its DCs }
  967. procedure TMouseManager.EndIconCursor( TheX , TheY : Integer );
  968. var WorkingPoint1 ,
  969.     WorkingPoint2 : TPoint;
  970. begin
  971.   IconCursor := false;
  972.   WorkingPoint1.X := Old_X - 16;
  973.   WorkingPoint1.Y := Old_Y - 16;
  974.   WorkingPoint2.X := Old_X + 17;
  975.   WorkingPoint2.Y := Old_Y + 17;
  976.   {Put the saved bitmap onto the workspace canvas}
  977.   with WorkspaceBMP.Canvas do
  978.   begin
  979.     CopyMode := cmSrcCopy;
  980.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  981.        BackGroundBMP.Canvas , Rect( 0 , 0 , 33 ,  33 ));
  982.   end;
  983.   {Copy the workspace bitmap onto the visible screen}
  984.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  985.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  986.   ReleaseDC( 0 , GlobalDC );
  987.   Screen.Cursor := StoredCursor;
  988. end;
  989.  
  990. { This procedure starts the animated icon cursor }
  991. procedure TMouseManager.StartAnimatedIconCursor( TheX , TheY : Integer );
  992. begin
  993.   StartIconCursor( TheX , TheY );
  994.   TheTimer.Enabled := true;
  995.   CurrentAnimationPointer := 1;
  996. end;
  997.  
  998. { This procedue ends the animated icon cursor }
  999. procedure TMouseManager.EndAnimatedIconCursor( TheX , TheY : Integer );
  1000. begin
  1001.   EndIconCursor( TheX , TheY );
  1002.   TheTimer.Enabled := false;
  1003.   CursorIcon := TIcon( TheAnimationList[ 0 ] );
  1004. end;
  1005.  
  1006. { This procedure moves the animated icon cursor }
  1007. procedure TMouseManager.MoveAnimatedIconCursor( TheX , TheY : Integer );
  1008. begin
  1009.   MoveIconCursor( TheX , TheY );
  1010. end;
  1011.  
  1012. { This procedure switches icons on timer events and prompts a redraw }
  1013. procedure TMouseManager.TimerAction( Sender : TObject );
  1014. begin
  1015.   Inc( CurrentAnimationPointer );     
  1016.   if CurrentAnimationPointer > TheAnimationList.Count then
  1017.    CurrentAnimationPointer := 1;
  1018.   CursorIcon := TIcon( TheAnimationList[ CurrentAnimationPointer - 1 ] );
  1019.   MoveIconCursor( Old_X , Old_Y );
  1020. end;
  1021.  
  1022. { This function returns true if CAPSLOCK is down }
  1023. function TIoManager.IsCapsLockDown : Boolean;
  1024. begin
  1025.   if CLState then result := true else result := false;
  1026. end;
  1027.  
  1028. { This function returns true if NUMLOCK is down }
  1029. function TIoManager.ISNumLockDown : Boolean;
  1030. begin
  1031.   if NLState then result := true else result := false;
  1032. end;
  1033.  
  1034. { This function returns true if SCROLLLOCK is down }
  1035. function TIoManager.IsScrollLockDown : Boolean;
  1036. begin
  1037.   if SLState then result := true else result := false;
  1038. end;
  1039.  
  1040. { this function gets the values for CLState, NLState, and SLState }
  1041. procedure TIoManager.InitLocks;
  1042. var TheKeys : TKeyboardState;
  1043. begin
  1044.   GetKeyBoardState( TheKeys );
  1045.   CLState := (( TheKeys[ VK_Capital ] mod 2 ) = 1 );
  1046.   NLState := (( TheKeys[ VK_Numlock ] mod 2 ) = 1 );
  1047.   CLState := (( TheKeys[ VK_Scroll ] mod 2 ) = 1 );
  1048. end;
  1049.  
  1050. { This procedure returns the state of the three lock variables }
  1051. procedure TIoManager.ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  1052. begin
  1053.   TheCL := CLState;
  1054.   TheNL := NLState;
  1055.   TheSL := SLState;
  1056. end;
  1057.  
  1058. { This procedure sets the state of the three lock variables to the imported vals }
  1059. procedure TIoManager.SetLocks( TheCL , TheNL , TheSL : Boolean );
  1060. var TheKeys : TKeyBoardState;
  1061. begin
  1062.   GetKeyBoardState( TheKeys );
  1063.   CLState := TheCL;
  1064.   NLState := TheNL;
  1065.   SLState := TheSL;
  1066.   if ClState then TheKeys[ VK_Capital ] := 1 else
  1067.    TheKeys[ VK_Capital ] := 0;
  1068.   if NLState then TheKeys[ VK_Numlock ] := 1 else
  1069.    TheKeys[ VK_Numlock ] := 0;
  1070.   if SLState then TheKeys[ VK_Scroll ] := 1 else
  1071.    TheKeys[ VK_Scroll ] := 0;
  1072.   SetKeyBoardState( TheKeys );
  1073. end;
  1074.  
  1075. { This procedure handles pressing of F1 for CCFileManagerForm }
  1076. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  1077.   Shift: TShiftState);
  1078. begin
  1079.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  1080. end;
  1081.  
  1082. { This procedure handles pressing of F2 for CCFileManagerForm }
  1083. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  1084.   Shift: TShiftState);
  1085. begin
  1086.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  1087. end;
  1088.  
  1089. { This procedure handles pressing of F3 for CCFileManagerForm }
  1090. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  1091.   Shift: TShiftState);
  1092. begin
  1093.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  1094. end;
  1095.  
  1096. { This procedure handles pressing of F4 for CCFileManagerForm }
  1097. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  1098.   Shift: TShiftState);
  1099. begin
  1100.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  1101. end;
  1102.  
  1103. { This procedure handles pressing of F5 for CCFileManagerForm }
  1104. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  1105.   Shift: TShiftState);
  1106. begin
  1107.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  1108. end;
  1109.  
  1110. { This procedure handles pressing of F6 for CCFileManagerForm }
  1111. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  1112.   Shift: TShiftState);
  1113. begin
  1114.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  1115. end;
  1116.  
  1117. { This procedure handles pressing of F7 for CCFileManagerForm }
  1118. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  1119.   Shift: TShiftState);
  1120. begin
  1121.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  1122. end;
  1123.  
  1124. { This procedure handles pressing of F8 for CCFileManagerForm }
  1125. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  1126.   Shift: TShiftState);
  1127. begin
  1128.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  1129. end;
  1130.  
  1131. { This procedure handles pressing of F9 for CCFileManagerForm }
  1132. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  1133.   Shift: TShiftState);
  1134. begin
  1135.   TCCFileMgrForm( Parent ).BitBtn11Click( Sender );
  1136. end;
  1137.  
  1138. { This procedure handles pressing of F10 for CCFileManagerForm }
  1139. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  1140.   Shift: TShiftState);
  1141. begin
  1142.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  1143. end;
  1144.  
  1145. { This procedure handles pressing of F11 for CCFileManagerForm }
  1146. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  1147.   Shift: TShiftState);
  1148. begin
  1149.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  1150. end;
  1151.  
  1152. { This procedure handles pressing of F12 for CCFileManagerForm }
  1153. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  1154.   Shift: TShiftState);
  1155. begin
  1156.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  1157. end;
  1158.  
  1159. { Returns True if the Left Button was pressed in the last mouse operation }
  1160. function TIOManager.WasLeftPressed : Boolean;
  1161. begin
  1162.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  1163.    WasLeftPressed := false;
  1164. end;
  1165.  
  1166. { Returns true if the Right Button was pressed in the last mouse operation }
  1167. function TIOManager.WasRightPressed : Boolean;
  1168. begin
  1169.   if mbRight = WhichButton then WasRightPressed := true else
  1170.    WasRightPressed := false;
  1171. end;
  1172.  
  1173. { Returns true if the Middle Button was pressed in the last mouse operation }
  1174. function TIOManager.WasMiddlePressed : Boolean;
  1175. begin
  1176.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  1177.    WasMiddlePressed := false;
  1178. end;
  1179.  
  1180. { Returns true if the ALT key was down during the last IO operation }
  1181. function TIOManager.WasALTPressed : Boolean;
  1182. begin
  1183.   if ssAlt in WhichState then WasALTPressed := true else
  1184.    WasALTPressed := false;
  1185. end;
  1186.  
  1187. { Returns true if either SHIFT key was down during the last IO operation }
  1188. function TIOManager.WasSHIFTPressed : Boolean;
  1189. begin
  1190.   if ssShift in WhichState then WasSHIFTPressed := true else
  1191.    WasSHIFTPressed := false;
  1192. end;
  1193.  
  1194. { Returns true if the Control Key was down during the last IO operation }
  1195. function TIOManager.WasCTRLPressed : Boolean;
  1196. begin
  1197.   if ssCtrl in WhichState then WasCTRLPressed := true else
  1198.    WasCTRLPressed := false;
  1199. end;
  1200.  
  1201.  
  1202. { This procedure does a fully error-trapped change directory }
  1203. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  1204. var CurrentDirectory : String;
  1205. begin
  1206.   if NewPath = '..' then
  1207.   begin { Back up one level }
  1208.     {$I+}
  1209.     try
  1210.       { Find the current directory }
  1211.       GetDir( 0 , CurrentDirectory );
  1212.       { Use EFP to move up one level }
  1213.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  1214.       { Strip trailing \ if not root }
  1215.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1216.       { Try the change to the New drive }
  1217.       ChDir( CurrentDirectory );
  1218.     except
  1219.       { if any exception occurs instantiate exception and show }
  1220.       On E:EInOutError do
  1221.       begin
  1222.         { Call custom error display/lookup procedure }
  1223.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1224.          E.Message , E.ErrorCode );
  1225.       end;
  1226.     end;
  1227.   end
  1228.   else
  1229.   begin { Change to explicit path }
  1230.     {$I+}
  1231.     try
  1232.       { Get target directory path }
  1233.       CurrentDirectory := NewPath;
  1234.       { Strip trailing \ if not root }
  1235.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1236.       { Try the change to the New drive }
  1237.       ChDir( CurrentDirectory );
  1238.     except
  1239.       { if any exception occurs instantiate exception and show }
  1240.       On E:EInOutError do
  1241.       begin
  1242.         { Call custom error display/lookup procedure }
  1243.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1244.          E.Message , E.ErrorCode );
  1245.       end;
  1246.     end;
  1247.   end;
  1248. end;
  1249.  
  1250. { This procedure does a fully error-trapped change directory }
  1251. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  1252. var CurrentDirectory : String;
  1253. begin
  1254.   {$I+}
  1255.   try
  1256.     { Find the working directory on New drive }
  1257.     GetDir( NewDrive , CurrentDirectory );
  1258.     { Try the change to the New drive }
  1259.     ChDir( CurrentDirectory );
  1260.   except
  1261.     { if any exception occurs instantiate exception and show }
  1262.     On E:EInOutError do
  1263.     begin
  1264.       { Call custom error display/lookup procedure }
  1265.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1266.        E.Message , E.ErrorCode );
  1267.     end;
  1268.   end;
  1269. end;
  1270.  
  1271. { This procedure copies a single file with error trapping }
  1272. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  1273. var AResult : Boolean; { Internal data flag }
  1274. begin
  1275.   { If Copyfile returns false an error occurred }
  1276.   AResult := CopyFile( OldPath , NewPath +
  1277.    ExtractFileName( OldPath ));
  1278.   { Display meaningful error message }
  1279.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  1280. end;
  1281.  
  1282. { This procedure moves a file by copying and delete it }
  1283. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  1284. var AResult : Boolean; { Internal data flag }
  1285.     TheFile : File;    { Use to get errors  }
  1286. begin
  1287.   { If Copyfile returns false an error occurred }
  1288.   AResult := CopyFile( OldPath , NewPath +
  1289.     ExtractFileName( OldPath ));
  1290.   { Display meaningful error message }
  1291.   if not AResult then HandleDOSError( GlobalErrorType ,
  1292.     OldPath , GlobalError );
  1293.   { After valid copying, delete source file }
  1294.   {$I+}
  1295.   if AResult then try
  1296.     { Use this trick to get valid exception handling }
  1297.     AssignFile( TheFile , OldPath );
  1298.     { Use erase because Deletefile doesn't give exceptions! }
  1299.     Erase( TheFile );
  1300.   except
  1301.     { if any exception occurs instantiate exception and show }
  1302.     On E:EInOutError do
  1303.     begin
  1304.       { Call custom error display/lookup procedure }
  1305.       HandleIOException( EOC_DELETEFILE , OldPath ,
  1306.        E.Message , E.ErrorCode );
  1307.     end;
  1308.   end;
  1309. end;
  1310.  
  1311. { This procedure safely deletes a single file }
  1312. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  1313. var TheFile : File; { Internal file handle }
  1314. begin
  1315.   {$I+}
  1316.   try
  1317.     { Use this trick to get valid exception handling }
  1318.     AssignFile( TheFile , ThePath );
  1319.     { Use erase because Deletefile doesn't give exceptions! }
  1320.     Erase( TheFile );
  1321.   except
  1322.     { if any exception occurs instantiate exception and show }
  1323.     On E:EInOutError do
  1324.     begin
  1325.       { Call custom error display/lookup procedure }
  1326.       HandleIOException( EOC_DELETEFILE , ThePath ,
  1327.        E.Message , E.ErrorCode );
  1328.     end;
  1329.   end;
  1330. end;
  1331.  
  1332. { This procedure renames a file with full error trapping }
  1333. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  1334. var TheFile : File; { Internal file handle }
  1335. begin
  1336.   {$I+}
  1337.   try
  1338.     { Use this trick to get valid exception handling }
  1339.     AssignFile( TheFile , OldPath );
  1340.     { Use this because RenameFile doesn't give exceptions! }
  1341.     Rename( TheFile , NewName );
  1342.   except
  1343.     { if any exception occurs instantiate exception and show }
  1344.     On E:EInOutError do
  1345.     begin
  1346.       { Call custom error display/lookup procedure }
  1347.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  1348.        E.Message , E.ErrorCode );
  1349.     end;
  1350.   end;
  1351. end;
  1352.  
  1353. { This procedure creates a New directory with full error trapping }
  1354. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  1355. begin
  1356.   {$I+}
  1357.   try
  1358.     Mkdir( NewPath );
  1359.   except
  1360.     { if any exception occurs instantiate exception and show }
  1361.     On E:EInOutError do
  1362.     begin
  1363.       { Call custom error display/lookup procedure }
  1364.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  1365.        E.Message , E.ErrorCode );
  1366.     end;
  1367.   end;
  1368. end;
  1369.  
  1370. { This procedure remove a directory with full error trapping }
  1371. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  1372. begin
  1373.   {$I+}
  1374.   try
  1375.     Rmdir( ThePath );
  1376.   except
  1377.     { if any exception occurs instantiate exception and show }
  1378.     On E:EInOutError do
  1379.     begin
  1380.       { Call custom error display/lookup procedure }
  1381.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  1382.        E.Message , E.ErrorCode );
  1383.     end;
  1384.   end;
  1385. end;
  1386.  
  1387. { Use this to set the attributes of a file with error trapping }
  1388. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  1389.            TheAttributes : Integer );
  1390. var TheResult : Integer; { Holds error code if any }
  1391. begin
  1392.   { Attempt to set the attributes }
  1393.   TheResult := FileSetAttr( TheFile , TheAttributes );
  1394.   { if negative number error, so signal }
  1395.   if TheResult < 0 then
  1396.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  1397. end;
  1398.  
  1399. { This procedure recursively copies a directory to a New path }
  1400. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  1401. var TheDir : String; { Holds source directory }
  1402. begin
  1403.   { Get the source directory to copy }
  1404.   TheDir := ExtractFileName( OldPath );
  1405.   { Force a backslash to the Newpath variable }
  1406.   NewPath := ForceTrailingBackSlash( NewPath );
  1407.   { Add the source directory to the target path }
  1408.   NewPath := NewPath + TheDir;
  1409.   { Create a New directory with the New name }
  1410.   CreateNewDirectory( NewPath );
  1411.   { Force a backslash for compatibility }
  1412.   NewPath := FOrcetrailingBackSlash( NewPath );
  1413.   { Do the recursive call }
  1414.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  1415. end;
  1416.  
  1417. { This procedure recursively moves a directory tree }
  1418. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  1419. var TheDir    : String; { Holds source directory  }
  1420.     SavedPath : String; { Holds saved dir to kill }
  1421. begin
  1422.   { Get the source directory to move }
  1423.   TheDir := ExtractFileName( OldPath );
  1424.   { Force a backslash to the Newpath variable }
  1425.   NewPath := ForceTrailingBackSlash( NewPath );
  1426.   { Save the starting path just in case }
  1427.   SavedPath := OldPath;
  1428.   { Add the source directory to the target path }
  1429.   NewPath := NewPath + TheDir;
  1430.   { Create a New directory with the New name }
  1431.   CreateNewDirectory( NewPath );
  1432.   { Force a backslash for compatibility }
  1433.   NewPath := FOrcetrailingBackSlash( NewPath );
  1434.   { Do the recursive call }
  1435.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  1436.   { Remove the source directory }
  1437.   RemoveDirectory( SavedPath );
  1438. end;
  1439.  
  1440. { This procedure handles recursively deleting an entire directory tree }
  1441. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  1442. begin
  1443.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  1444. end;
  1445.  
  1446.  
  1447. { This is the generic routine to copy, move, and delete whole directory trees }
  1448. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  1449.            ActionCode : Integer );
  1450. { VITAL!!! These variables MUST be local for recursrion to work! }
  1451. var
  1452.     Finished        : Boolean;         { Loop flag              }
  1453.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1454.     TheResult       : Integer;         { return variable        }
  1455.     TargetPath ,
  1456.     FileMask   ,
  1457.     TheWorkingDirectory ,
  1458.     TheStoredWorkingDirectory ,
  1459.     ModifiedDirectory  : String;       { path for FF/FN         }
  1460.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1461.     ButtonColor   ,                    { main panel color       }
  1462.     ButtonHLColor ,                    { bright panel color     }
  1463.     ButtonSColor  ,                    { dark panel color       }
  1464.     Textcolor       : TColor;          { label text color       }
  1465.     TheFile         : File;
  1466.  
  1467. begin
  1468.   { Set up the initial variables }
  1469.   Finished := false;
  1470.   TheWorkingDirectory := StartingPath;
  1471.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1472.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  1473.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  1474.   { Make the call to FindFirst set to get any file }
  1475.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1476.   { loop through all files in the directory and delete them }
  1477.   while not Finished do
  1478.   begin
  1479.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1480.     TheResult := FindNext( TheSR );
  1481.     { A -1 result means no more files so exit }
  1482.     if TheResult < 0 then finished := true else
  1483.     begin
  1484.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1485.        <> faDirectory ) then
  1486.       begin { A File }
  1487.         case ActionCode of
  1488.           FAC_COPY :
  1489.               begin
  1490.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  1491.               end;
  1492.           FAC_MOVE :
  1493.               begin
  1494.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  1495.               end;
  1496.           FAC_DELETE :
  1497.               begin { Delete }
  1498.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  1499.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1500.                     DeleteTheFile( TargetPath + TheSR.Name );
  1501.               end;
  1502.         end;
  1503.       end;
  1504.     end;
  1505.   end;
  1506.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1507.   FindClose( TheSR );
  1508.   { Set up the variables to do recursive calls on all directories}
  1509.   Finished := false;
  1510.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  1511.   { Make the call to FindFirst set to get any file, ignore result }
  1512.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1513.   while not Finished do
  1514.   begin
  1515.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1516.     TheResult := FindNext( TheSR );
  1517.     { A -1 result means no more files so exit }
  1518.     if TheResult < 0 then
  1519.       finished := true
  1520.     else
  1521.     begin
  1522.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1523.       begin
  1524.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1525.          = faDirectory ) then
  1526.         begin
  1527.           { Send in the New directory name }
  1528.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  1529.            TheSR.Name;
  1530.           { Reproduce directory structure for recursion in copy/move }
  1531.           NewPath := NewPath + TheSR.Name;
  1532.           case ActionCode of
  1533.             FAC_COPY , FAC_MOVE :
  1534.                begin { Create ahead for move and copy }
  1535.                  { Make the New directory for moving and copying }
  1536.                  CreateNewDirectory( NewPath );
  1537.                  { Force a backslash for compatibility }
  1538.                  NewPath := ForceTrailingBackSlash( NewPath );
  1539.                end;
  1540.             FAC_DELETE :
  1541.                begin  { No prior action needed for Delete }
  1542.                end;
  1543.           end;
  1544.           { Do the recursive call }
  1545.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  1546.           case ActionCode of
  1547.             FAC_COPY :
  1548.                begin { no action for copy }
  1549.                end;
  1550.             FAC_MOVE , FAC_DELETE :
  1551.                begin  { Delete }
  1552.                  { Get a confirmation }
  1553.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  1554.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1555.                    RemoveDirectory( TargetPath + TheSR.Name );
  1556.                end;
  1557.           end;
  1558.         end;
  1559.       end;
  1560.     end;
  1561.   end;
  1562. end;
  1563.  
  1564. { This is a generic copy routine taken from Delphi sample code }
  1565. { This function calls the sample Copy code and handles errors }
  1566. function TFileWorkBench.CopyFile( TargetPath ,
  1567.           DestinationPath : String ) : Boolean;
  1568. begin
  1569.   { Set global error value to no error }
  1570.   GlobalError := 0;
  1571.   { Call the sample procedure to do the copy }
  1572.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  1573.   { If no error return true else return false }
  1574.   if GlobalError < 0 then CopyFile := false else
  1575.    CopyFile := true;
  1576. end;
  1577.  
  1578. { This procedure handles displaying a user-friendly Dialog box with a }
  1579. { Message for Delphi IO exception errors.                             }
  1580. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  1581.            ThePath : String; TheMessage : String; TheCode : Integer );
  1582. var ErrorMessageString : String;  { Holds internal data }
  1583.     OperationString    : String;  { Holds internal data }
  1584. begin
  1585.   { clear to check for unrecognized code }
  1586.   ErrorMessageString := '';
  1587.   { Check against imported code }
  1588.   case TheCode of
  1589.     2    : ErrorMessageString := 'File not found';
  1590.     3    : ErrorMessageString := 'Path not found';
  1591.     4    : ErrorMessageString := 'Too many open files';
  1592.     5    : ErrorMessageString := 'File access denied';
  1593.     6    : ErrorMessageString := 'Invalid file handle';
  1594.     12    : ErrorMessageString := 'Invalid file access code';
  1595.     15    : ErrorMessageString := 'Invalid drive number';
  1596.     16  : ErrorMessageString := 'Cannot remove current directory';
  1597.     17    : ErrorMessageString := 'Cannot rename across drives';
  1598.     100    : ErrorMessageString := 'Disk read error';
  1599.     101    : ErrorMessageString := 'Disk write error';
  1600.     102    : ErrorMessageString := 'File not assigned';
  1601.     103    : ErrorMessageString := 'File not open';
  1602.     104    : ErrorMessageString := 'File not open for input';
  1603.     105    : ErrorMessageString := 'File not open for output';
  1604.   end;
  1605.   case TheOpCode of
  1606.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1607.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1608.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1609.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1610.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1611.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1612.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1613.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1614.   end;
  1615.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  1616.   if ErrorMessageString = '' then
  1617.   begin
  1618.     Screen.Cursor := crDefault;
  1619.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1620.      TheMessage , mtError , [mbOK],0);
  1621.   end
  1622.   else
  1623.   begin
  1624.     { Recognized DOS exception, reset cursor for neatness }
  1625.     Screen.Cursor := crDefault;
  1626.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1627.      ErrorMessageString , mtError , [mbOK], 0 );
  1628.   end;
  1629. end;
  1630.  
  1631. { This procedure handles displaying a user-friendly Dialog box with a }
  1632. { Message for DOS error codes.                                        }
  1633. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  1634.            ThePath : String;  TheCode : Integer );
  1635. var ErrorMessageString : String;  { internal message holder }
  1636.     OperationString : String;     { internal message holder }
  1637. begin
  1638.   { clear the message holder to check for unrecognized code }
  1639.   ErrorMessageString := '';
  1640.   { Negate the code back to normal number and check to set string }
  1641.   case -TheCode of
  1642.     2    : ErrorMessageString := 'File not found';
  1643.     3    : ErrorMessageString := 'Path not found';
  1644.     4    : ErrorMessageString := 'Too many open files';
  1645.     5    : ErrorMessageString := 'File access denied';
  1646.     6    : ErrorMessageString := 'Invalid file handle';
  1647.     12    : ErrorMessageString := 'Invalid file access code';
  1648.     15    : ErrorMessageString := 'Invalid drive number';
  1649.     16  : ErrorMessageString := 'Cannot remove current directory';
  1650.     17    : ErrorMessageString := 'Cannot rename across drives';
  1651.     100    : ErrorMessageString := 'Disk read error';
  1652.     101    : ErrorMessageString := 'Disk write error';
  1653.     102    : ErrorMessageString := 'File not assigned';
  1654.     103    : ErrorMessageString := 'File not open';
  1655.     104    : ErrorMessageString := 'File not open for input';
  1656.     105    : ErrorMessageString := 'File not open for output';
  1657.     157 : ErrormessageString := 'Could not open Source File';
  1658.     159 : ErrormessageString := 'Could not open Target File';
  1659.   end;
  1660.   case TheOpCode of
  1661.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1662.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1663.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1664.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1665.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1666.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1667.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1668.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1669.   end;
  1670.   { If the string is empty an unrecognized code was sent in }
  1671.   if ErrorMessageString = '' then
  1672.   begin
  1673.     { Sent up db based on source or target error; reset cursor for neatness }
  1674.     Screen.Cursor := crDefault;
  1675.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  1676.      IntToStr( TheCode ) , mtError , [mbOK],0);
  1677.   end
  1678.   else  { Code is recognized, use message from case statement }
  1679.   begin
  1680.     { Format the output for source or target error }
  1681.     Screen.Cursor := crDefault;
  1682.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1683.      ErrorMessageString , mtError , [mbOK], 0 );
  1684.   end;
  1685. end;
  1686.  
  1687. { This procedure sets the imported booleans to the file's attributes }
  1688. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  1689.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  1690.             IsSysFile : Boolean );
  1691. var TheResult : Integer; { Traps for error code on VolumeID }
  1692. begin
  1693.   { Clear the imported flags for default }
  1694.   IsDirectory := false;
  1695.   IsArchive := false;
  1696.   IsVolumeID := false;
  1697.   IsHidden := False;
  1698.   IsReadOnly := false;
  1699.   IsSysFile := false;
  1700.   { Make the Dos call }
  1701.   TheResult := FileGetAttr( TheFile );
  1702.   if TheResult < 0 then
  1703.   begin
  1704.     { Volume ID returns -2 (?) }
  1705.     IsVolumeID := true;
  1706.     { It has no other properties }
  1707.     exit;
  1708.   end;
  1709.   { Use AND test to set all other properties }
  1710.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  1711.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  1712.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  1713.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  1714.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  1715.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  1716. end;
  1717.  
  1718. { This function makes sure a pathname has a trailing \ }
  1719. function TFileWorkBench.ForceTrailingBackSlash(
  1720.           const TheFileName : String ) : String;
  1721. var TempString : String;  { Used to hold function result }
  1722. begin
  1723.   { If no trailing \ add one (root will already have one.) }
  1724.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  1725.    TempString := TheFileName + '\' else TempString := TheFileName;
  1726.   { Return modified or non-modified string }
  1727.   ForceTrailingBackslash := TempString;
  1728. end;
  1729.  
  1730. { This function makes sure a non-root dir has no trailing \ }
  1731. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1732.           const TheFileName : String ) : String;
  1733. var TempString : String ; { Used to hold function result }
  1734. begin
  1735.   { Default is no change }
  1736.   TempString := TheFileName;
  1737.   { If not root then }
  1738.   if Length( TheFileName ) > 3 then
  1739.   begin
  1740.     { If has a trailing backslash remove it }
  1741.     if TheFileName[ Length( TheFileName )] = '\' then
  1742.     begin
  1743.       TempString := Copy( TheFileName , 1 ,
  1744.        Length( TheFileName ) - 1 );
  1745.     end;
  1746.   end;
  1747.   { Export the final result }
  1748.   StripNonRootTrailingBackSlash := TempString;
  1749. end;
  1750.  
  1751. { This gets the next selected listbox item }
  1752. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1753.           var CurrentItem : Integer ): String;
  1754. var TheResult : String;  { Internal storage }
  1755.     finished  : boolean; { Loop flag        }
  1756. begin
  1757.   { If out of items to check signal and exit }
  1758.   if CurrentItem > Items.Count then TheResult := '' else
  1759.   begin
  1760.     { Otherwise scan from current position till match or end }
  1761.     finished := false;
  1762.     while not finished do
  1763.     begin
  1764.       { Check against selected property }
  1765.       if Selected[ CurrentItem - 1 ] then
  1766.       begin
  1767.         { If selected then return it and abort loop }
  1768.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1769.         finished := true;
  1770.         { Increment current position }
  1771.         CurrentItem := CurrentItem + 1;
  1772.      end
  1773.       else
  1774.       begin
  1775.         { Increment current position }
  1776.         CurrentItem := CurrentItem + 1;
  1777.         { Otherwise check for end of data and abort if out of entries }
  1778.         if CurrentItem > Items.Count then
  1779.         begin
  1780.           TheResult := '';
  1781.           finished := true;
  1782.         end;
  1783.       end;
  1784.     end;
  1785.   end;
  1786.   { Return stored result }
  1787.   GetNextSelection := TheResult;
  1788. end;
  1789.  
  1790. { Modified from VCL Source Copyright 1995 }
  1791. { Borland International, Inc.             }
  1792. { Use this to override display with icons }
  1793. procedure TIconFileListBox.ReadFileNames;
  1794. var
  1795.   AttrIndex   : TFileAttr;
  1796.   i           : Integer;
  1797.   FileExt     : string;
  1798.   MaskPtr     : PChar;
  1799.   Ptr         : PChar;
  1800.   AttrWord    : Word;
  1801.   TempPicture : TPicture;
  1802.   TempBmp     : TBitmap;
  1803.   TempIcon    : TIcon;
  1804. const
  1805.   Attributes: array[TFileAttr] of Word =
  1806.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1807.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1808. begin
  1809.   { if no handle allocated yet, this call will force         }
  1810.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1811.   { In due time, one will be allocated appropriately.        }
  1812.   AttrWord := DDL_READWRITE;
  1813.   if HandleAllocated then
  1814.   begin
  1815.     { Set attribute flags based on values in FileType }
  1816.     for AttrIndex := ftReadOnly to ftArchive do
  1817.      if AttrIndex in FileType then
  1818.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1819.  
  1820.     { Use Exclusive bit to exclude normal files }
  1821.     if not ( ftNormal in FileType ) then
  1822.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1823.  
  1824.     ChDir( FDirectory ); { go to the directory we want }
  1825.     Clear;               { clear the list }
  1826.  
  1827.     MaskPtr := FMask;
  1828.     while MaskPtr <> nil do
  1829.     begin
  1830.       Ptr := StrScan ( MaskPtr , ';' );
  1831.       if Ptr <> nil then  Ptr^ := #0;
  1832.       { build the list }
  1833.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1834.       if Ptr <> nil then
  1835.       begin
  1836.         Ptr^ := ';';
  1837.         Inc ( Ptr );
  1838.       end;
  1839.       MaskPtr := Ptr;
  1840.     end;
  1841.     { Now add the bitmaps }
  1842.     {---------------------------- begin custom code --------------------------}
  1843.     { Create the TPicture for exchange purposes }
  1844.     TempPicture := TPicture.Create;
  1845.     { Set it to icon widths }
  1846.     TempPicture.Bitmap.Width := 32;
  1847.     TempPicture.Bitmap.Height := 32;
  1848.     { Run down the list }
  1849.     for i := 0 to Items.Count - 1 do
  1850.     begin
  1851.       { Create a New temporary icon }
  1852.       TempIcon := TIcon.Create;
  1853.       { Call the custom DRWS routine to get icon for a file }
  1854.       GetIconForFile( Items[ i ] , TempIcon );
  1855.       { Put the icon on the bitmap for the picture via draw }
  1856.       { Note 1 , 1 due to bug in Draw?                      }
  1857.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1858.       { Create a temporary bitmap }
  1859.       TempBmp := TBitmap.Create;
  1860.       { Set its width to those of the previous object's bitmaps }
  1861.       TempBmp.Width := 16;
  1862.       TempBmp.Height := 15;
  1863.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1864.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1865.        TempPicture.Bitmap );
  1866.       { Set the Objects list to the bitmap }
  1867.       Items.Objects[ i ] := TempBmp;
  1868.       { Free the icon each iteration; don't free the TempBmp as list does }
  1869.       TempIcon.Free;
  1870.     end;
  1871.     { Free the TPicture exchange element }
  1872.     TempPicture.Free;
  1873.     {------------------------ end custom code --------------------------------}
  1874.     Change;
  1875.   end;
  1876. end;
  1877.  
  1878. { Use this to respond to dbl-clicking FLB filename }
  1879. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1880. begin
  1881.   { Call shellexec as a wrapper around ShellExecute API call }
  1882.   { False indicates failure, signal error                    }
  1883.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1884.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1885.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1886. end;
  1887.  
  1888. { Create method for FIP                                }
  1889. constructor TIconFileListBox.Create( AOwner : TComponent );
  1890. begin
  1891.   { call inherited -- VITAL! }
  1892.   inherited Create( AOwner );
  1893.   { set the mouse method }
  1894.   OnDblClick := TheDblClick;
  1895. end;
  1896.  
  1897. { Create method for FIP                                }
  1898. constructor TFileIconPanel.Create( AOwner : TComponent );
  1899. begin
  1900.   { call inherited -- VITAL! }
  1901.   inherited Create( AOwner );
  1902.   { create icon and label components, making self owner/displayer }
  1903.   FTheIcon := TIcon.Create;
  1904.   FTheLabel := TLabel.Create( Self );
  1905.   FThelabel.Parent := Self;
  1906.   { Set own and labels mouse methods to stored methods }
  1907.   OnMouseUp := TheMouseUp;
  1908.   OnMouseDown := TheMouseDown;
  1909.   OnMouseMove := TheMouseMove;
  1910.   OnDragOver := TheDragOver;
  1911.   OnDragDrop := TheDragDrop;
  1912.   { Set alignment and autosize properties of the label }
  1913.   FTheLabel.Autosize := false;
  1914.   FTheLabel.Alignment := taCenter;
  1915.   { Set selected to false }
  1916.   Selected := false;
  1917. end;
  1918.  
  1919. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1920. var CurrentDirectory : String;    { Use to store dirs }
  1921.     TheDrive         : String;    { Get drive letter  }
  1922.     WhichDrive       : Integer;   { Get drive number  }
  1923.     ErrorCheck       : Integer;
  1924.     TheFWB           : TFileWorkBench;
  1925. begin
  1926.   { Create FileWorkBench for later use }
  1927.   TheFWB := TFileWorkBench.Create( Self );
  1928.   { Check for label or FIP sender }
  1929.   if FTheLabel.Caption = '..' then
  1930.   begin { deal with backup request }
  1931.     { Change to New directory }
  1932.     TheFWB.ChangeTheDirectory( '..' );
  1933.     { Call special method due to SendMessage problem! }
  1934.     TFileIconPanelScrollBox( Parent ).Update;
  1935.   end
  1936.   else
  1937.   begin
  1938.     { Check for DRIVE id in name }
  1939.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1940.     begin { Double Click on a Drive Icon }
  1941.       { Pull out the letter from name }
  1942.       TheDrive := Copy( FtheName , 7 , 1 );
  1943.       { Convert it to a number }
  1944.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1945.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1946.       { Call special method due to SendMessage problem! }
  1947.       TFileIconPanelScrollBox( Parent ).Update;
  1948.     end
  1949.     else
  1950.     begin { Double click on a dir/file icon }
  1951.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1952.       begin { A directory, change to it }
  1953.         { Since full path in name, simply change to it! }
  1954.         TheFWB.ChangeTheDirectory( FTheName );
  1955.         { Call special method due to SendMessage problem! }
  1956.         TFileIconPanelScrollBox( Parent ).Update;
  1957.       end
  1958.       else
  1959.       begin { A file; attempt to shellexecute it }
  1960.         { Call shellexec as a wrapper around ShellExecute API call }
  1961.         { False indicates failure, signal error                    }
  1962.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1963.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1964.           [mbOK], 0);
  1965.       end;
  1966.     end;
  1967.   end;
  1968.   TheFWB.Free; { This prevents resource leak }
  1969. end;
  1970.  
  1971. { Initialization method for FIP                                         }
  1972. procedure TFileIconPanel.Initialize( PanelX              ,
  1973.                                      PanelY              ,
  1974.                                      PanelWidth          ,
  1975.                                      PanelHeight         ,
  1976.                                      PanelBevelWidth     ,
  1977.                                      LabelFontSize         : Integer;
  1978.                                      PanelColor          ,
  1979.                                      PanelHighlightColor ,
  1980.                                      PanelShadowColor    ,
  1981.                                      LabelTextColor        : TColor;
  1982.                                      TheFilename         ,
  1983.                                      LabelFontName         : String;
  1984.                                      LabelFontStyle        : TFontStyles;
  1985.                                      ExtraData             : Integer );
  1986.  
  1987. var TheLabelHeight ,             { Holder for label pixel height }
  1988.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1989.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1990.     HolderBMP        : TBitmap;  { Holds working bitmap for tnail}
  1991.     HoldName         : String;
  1992. begin
  1993.   { Set the basic properties based on imported parameters }
  1994.   Left := PanelX;
  1995.   Top := PanelY;
  1996.   Width := PanelWidth;
  1997.   Height := PanelHeight;
  1998.   Color := PanelColor;
  1999.   BevelWidth := PanelBevelWidth;
  2000.   FHighlightColor := PanelHighlightColor;
  2001.   FShadowColor := PanelShadowColor;
  2002.   FTheName := TheFilename;
  2003.   { If the ExtraData field is non-0 then a drive is being sent in }
  2004.   if ExtraData <> 0 then
  2005.   begin
  2006.     { Use the data field value to determine which icon to get from RES file }
  2007.     case ExtraData of
  2008.       1 : begin
  2009.             GetMem( TheOtherPChar , 255 );
  2010.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  2011.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2012.             FreeMem( TheOtherPChar , 255 );
  2013.           end;
  2014.       2 : begin
  2015.             GetMem( TheOtherPChar , 255 );
  2016.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  2017.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2018.             FreeMem( TheOtherPChar , 255 );
  2019.           end;
  2020.       3 : begin
  2021.             GetMem( TheOtherPChar , 255 );
  2022.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  2023.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2024.             FreeMem( TheOtherPChar , 255 );
  2025.           end;
  2026.       4 : begin
  2027.             GetMem( TheOtherPChar , 255 );
  2028.             StrPCopy( TheOtherPChar , 'CDROM' );
  2029.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2030.             FreeMem( TheOtherPChar , 255 );
  2031.           end;
  2032.       5 : begin
  2033.             GetMem( TheOtherPChar , 255 );
  2034.             StrPCopy( TheOtherPChar , 'RAM' );
  2035.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2036.             FreeMem( TheOtherPChar , 255 );
  2037.           end;
  2038.     end;
  2039.     { The FileNme property is already set up for the caption; use directly }
  2040.     FTheLabel.Caption := TheFilename;
  2041.     { Set up the hint for later use (make sure to set ShowHint) }
  2042.     Hint := 'Change to ' + TheFileName;
  2043.     ShowHint := true;
  2044.     { Set up all imported label properties and center it for drawing }
  2045.     with FTheLabel do
  2046.     begin
  2047.       Font.Name := LabelFontName;
  2048.       Font.Size := LabelFontSize;
  2049.       Font.Style := LabelFontStyle;
  2050.       Font.Color := LabelTextColor;
  2051.       Canvas.Brush.Color := PanelColor;
  2052.       Canvas.Font := Font;
  2053.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2054.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2055.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2056.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2057.       Top := Top + Round( Self.Height * 0.75 );
  2058.       Height := TheLabelHeight;
  2059.       Width := TheLabelWidth;
  2060.     end;
  2061.   end
  2062.   else
  2063.   begin
  2064.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  2065.     { icon either from the file, its owner, or a RES file default.          }
  2066.     GetIconForFile( FTheName , FTheIcon );
  2067.     { Check for the Backup caption and set it specially }
  2068.     if ExtractfileName( FThename ) = '..' then
  2069.     begin
  2070.       FTheLabel.Caption := '..';
  2071.       Hint := 'Up One Level';
  2072.     end
  2073.     else
  2074.     begin
  2075.       if Uppercase( ExtractFileExt( FTheName )) = '.BMP' then
  2076.       begin
  2077.         HolderBMP := TBitmap.Create;
  2078.         HolderBMP.LoadFromFile( FTheName );
  2079.         FTheBMP := CreateBitmapThumbNailFromBitmap( HolderBMP , ThumbNailWidth ,
  2080.          ThumbNailHeight );
  2081.         HolderBMP.Free;
  2082.         HoldName := ExtractFileName( FTheName );
  2083.         HoldName := Copy( HoldName, 1 , Length( HoldName ) - 4 );
  2084.         HoldName := HoldName + '.THU';
  2085.         FTheBMP.SaveToFile( ExpandFileName( HoldName ));
  2086.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2087.         Hint := FTheName;
  2088.       end
  2089.       else
  2090.       begin
  2091.         { Otherwise just get the filename for the label caption }
  2092.         { And the full path for the hint (used later.)          }
  2093.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2094.         Hint := FTheName;
  2095.       end;
  2096.     end;
  2097.     { Activate showhint so hints are seen }
  2098.     ShowHint := true;
  2099.     { Set label properties with imported values and center for display }
  2100.     with FTheLabel do
  2101.     begin
  2102.       Font.Name := LabelFontName;
  2103.       Font.Size := LabelFontSize;
  2104.       Font.Style := LabelFontStyle;
  2105.       Font.Color := LabelTextColor;
  2106.       Canvas.Brush.Color := PanelColor;
  2107.       Canvas.Font := Font;
  2108.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2109.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2110.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2111.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2112.       Top := Top + Round( Self.Height * 0.75 );
  2113.       Height := TheLabelHeight;
  2114.       Width := TheLabelWidth;
  2115.     end;
  2116.   end;
  2117. end;
  2118.  
  2119. { Destroy method for FIP }
  2120. destructor TFileIconPanel.Destroy;
  2121. begin
  2122.   { free component resources }
  2123.   if assigned( FTheIcon ) then FTheIcon.Free;
  2124.   FTheLabel.Free;
  2125.   if Assigned( FTheBMP ) then FTheBMP.Free;
  2126.   { call inherited -- VITAL! }
  2127.   inherited Destroy;
  2128. end;
  2129.  
  2130. { Mousedown method for FIP; used to allow dragging }
  2131. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  2132.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2133. var ThePoint , TheOtherPoint : TPoint;
  2134. begin
  2135.   { Begin a conditional drag operation (false allows timer) }
  2136.   TheIOManager.WhichButton := Button;
  2137.   TheIOManager.WhichState := Shift;
  2138.   { Currently ignore drive clicks }
  2139.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  2140.   if (( Button = mbRight ) and ( ssShift in Shift )) then
  2141.   begin
  2142.     TheTempBitmap := TBitmap.Create;
  2143.     TheTempBitmap.Width := Self.Width;
  2144.     TheTempBitmap.Height := Self.Height;
  2145.     TheTempBitmap.Canvas.Copyrect( Rect( 0 , 0 , Self.Width , Self.Height ) ,
  2146.      Self.Canvas , Rect( 0 , 0 , Self.Width , Self.Height ));
  2147.     TheMouseManager.InitializeBitmap( TheTempBitmap );
  2148.     ThePoint.X := X;
  2149.     ThePoint.Y := Y;
  2150.     TheOtherPoint := ClientToScreen( ThePoint );
  2151.     TheMouseManager.StartBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2152.     BitmapDragging := true;
  2153.     GlobalSource := Self;
  2154.     exit;
  2155.   end;
  2156.   if Button = mbRight then
  2157.   begin
  2158.     TheMouseManager.InitializeIcon( FTheIcon );
  2159.     ThePoint.X := X;
  2160.     ThePoint.Y := Y;
  2161.     TheOtherPoint := ClientToScreen( ThePoint );
  2162.     TheMouseManager.StartIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2163.     IconDragging := true;
  2164.     GlobalSource := Self;
  2165.     exit;
  2166.   end;
  2167.   BeginDrag( false );
  2168.   { Flip status of bevels }
  2169.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  2170.    BevelOuter := bvRaised;
  2171.   { Flip selected variable }
  2172.   Selected := not Selected;
  2173.   { Set redisplay }
  2174. end;
  2175.  
  2176. procedure TFileIconPanel.TheMouseMove(Sender: TObject; Shift: TShiftState;
  2177.   X, Y: Integer);
  2178. var ThePoint, TheOtherPoint : TPoint;
  2179. begin
  2180.   if IconDragging then
  2181.   begin
  2182.     ThePoint.X := X;
  2183.     ThePoint.Y := Y;
  2184.     TheOtherPoint := ClientToScreen( ThePoint );
  2185.     TheMouseManager.MoveIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2186.     exit;
  2187.   end;
  2188.   if BitmapDragging then
  2189.   begin
  2190.     ThePoint.X := X;
  2191.     ThePoint.Y := Y;
  2192.     TheOtherPoint := ClientToScreen( ThePoint );
  2193.     TheMouseManager.MoveBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2194.     exit;
  2195.   end;
  2196. end;
  2197.  
  2198. { Mouseup Method for FIP; used to allow dragging }
  2199. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  2200.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2201. begin
  2202.   if IconDragging then
  2203.   begin
  2204.     TheMouseManager.EndIconCursor( X , Y );
  2205.     IconDragging := false;
  2206.     if GlobalSource <> Self then
  2207.     begin { Right-drag onto a panel! }
  2208.       TheDragDrop( Sender , GlobalSource , X , Y );
  2209.     end;
  2210.     exit;
  2211.   end;
  2212.   if BitmapDragging then
  2213.   begin
  2214.     TheMouseManager.EndBitmapCursor( X , Y );
  2215.     BitmapDragging := false;
  2216.     if GlobalSource <> Self then
  2217.     begin { Right-drag onto a panel! }
  2218.       TheDragDrop( Sender , GlobalSource , X , Y );
  2219.     end;
  2220.     exit;
  2221.   end;
  2222.   { End a drag operation without dropping; if dragged OK }
  2223.   { already handled.                                     }
  2224.   EndDrag( false );
  2225.   { If the right button is clicked, perform magic! }
  2226.   { Redisplay on general principles }
  2227.   Invalidate;
  2228. end;
  2229.  
  2230. { Use this to generically OK DnD from FIPs }
  2231. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  2232.   Y: Integer; State: TDragState; var Accept: Boolean);
  2233. begin
  2234.   { Only accept from FileIconPanel components }
  2235.   if Source is TFileIconPanel then Accept := true else Accept := false;
  2236. end;
  2237.  
  2238. { Use this to accept Drag and Drop from other FIPs }
  2239. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  2240.   Y: Integer);
  2241. var CurrentName ,                 { Holds work name}
  2242.     TheOldString : String;        { Holds Dir      }
  2243.     TargetDir    : String;        { target of op   }
  2244.     TheResult       : Integer;    { Modal res hold }
  2245.     SourceDirectory,
  2246.     TargetDirectory,
  2247.     CurrentDirectory : String;    { Use to store dirs }
  2248.     TheDrive         : String;    { Get drive letter  }
  2249.     WhichDrive       : Integer;   { Get drive number  }
  2250.     ErrorCheck       : Integer;
  2251.     TheFWB           : TFileWorkBench;
  2252.     ThePosition : Integer;
  2253.     Finished : Boolean;
  2254.     TheFIPSB : TFileIconPanelScrollBox;
  2255. begin
  2256.   { If drop target is .. then ignore }
  2257.   if FTheLabel.Caption = '..' then exit;
  2258.   { Likewise ignore Dnd from drive icons }
  2259.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  2260.   { Obtain the parent of the source FIP; may not be self }
  2261.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  2262.   { Obtain source directory either as Dir or filepath }
  2263.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  2264.    and faDirectory ) = faDirectory ) then
  2265.   begin  { Directory; take whole path }
  2266.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  2267.   end
  2268.   else
  2269.   begin { File; get pathname }
  2270.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2271.   end;
  2272.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  2273.   if Pos( 'DRIVE' , FTheName ) > 0 then
  2274.   begin { Drop onto a drive icon; perform action to its default dir }
  2275.     { Pull out the letter from name }
  2276.     TheDrive := Copy( FtheName , 7 , 1 );
  2277.     { Convert it to a number }
  2278.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  2279.     { Determine the target directory and drive }
  2280.     GetDir( WhichDrive , TargetDirectory );
  2281.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  2282.     { Check for shift to operate on all selections }
  2283.     if TheIOManager.WasSHIFTPressed then
  2284.     begin { Operate on all selections }
  2285.       { Obtain the parent directory of the FIP dragged over }
  2286.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2287.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2288.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2289.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2290.       begin
  2291.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2292.         exit;
  2293.       end;
  2294.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2295.       begin { Copy to different drives }
  2296.         if TheIOManager.WasALTPressed then
  2297.         begin { ALT overrides and does move }
  2298.           { Set up to get all current selections }
  2299.           ThePosition := 1;
  2300.           finished := false;
  2301.           while not finished do
  2302.           begin
  2303.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2304.                    ThePosition );
  2305.             { If returns blank string then out of selections }
  2306.             if CurrentName = '' then finished := true else
  2307.             begin
  2308.               { If a directory signal error }
  2309.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2310.               begin
  2311.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2312.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2313.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2314.                    TargetDirectory );
  2315.               end
  2316.               else
  2317.               begin
  2318.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2319.               end;
  2320.             end;
  2321.             { Reset to normal cursor }
  2322.             Screen.Cursor := crDefault;
  2323.           end;
  2324.         end
  2325.         else
  2326.         begin { Default is to do copy like file manager }
  2327.           { Set up to get all current selections }
  2328.           ThePosition := 1;
  2329.           finished := false;
  2330.           while not finished do
  2331.           begin
  2332.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2333.                    ThePosition );
  2334.             { If returns blank string then out of selections }
  2335.             if CurrentName = '' then finished := true else
  2336.             begin
  2337.               { If a directory signal error }
  2338.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2339.               begin
  2340.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2341.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2342.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2343.                    TargetDirectory );
  2344.               end
  2345.               else
  2346.               begin
  2347.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2348.               end;
  2349.             end;
  2350.             { Reset to normal cursor }
  2351.             Screen.Cursor := crDefault;
  2352.           end;
  2353.         end;
  2354.       end
  2355.       else
  2356.       begin { Copy to same drive }
  2357.         if TheIOManager.WasCTRLPressed then
  2358.         begin { CTRL overrides and does copy }
  2359.           { Set up to get all current selections }
  2360.           ThePosition := 1;
  2361.           finished := false;
  2362.           while not finished do
  2363.           begin
  2364.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2365.                    ThePosition );
  2366.             { If returns blank string then out of selections }
  2367.             if CurrentName = '' then finished := true else
  2368.             begin
  2369.               { If a directory signal error }
  2370.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2371.               begin
  2372.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2373.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2374.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2375.                    TargetDirectory );
  2376.               end
  2377.               else
  2378.               begin
  2379.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2380.               end;
  2381.             end;
  2382.             { Reset to normal cursor }
  2383.             Screen.Cursor := crDefault;
  2384.           end;
  2385.         end
  2386.         else
  2387.         begin { Default is to do move like file manager }
  2388.           { Set up to get all current selections }
  2389.           ThePosition := 1;
  2390.           finished := false;
  2391.           while not finished do
  2392.           begin
  2393.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2394.                    ThePosition );
  2395.             { If returns blank string then out of selections }
  2396.             if CurrentName = '' then finished := true else
  2397.             begin
  2398.               { If a directory signal error }
  2399.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2400.               begin
  2401.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2402.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2403.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2404.                    TargetDirectory );
  2405.               end
  2406.               else
  2407.               begin
  2408.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2409.               end;
  2410.             end;
  2411.             { Reset to normal cursor }
  2412.             Screen.Cursor := crDefault;
  2413.           end;
  2414.         end;
  2415.       end;
  2416.     end
  2417.     else
  2418.     begin { Operate on only source }
  2419.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2420.       begin { Copy to different drives }
  2421.         if TheIOManager.WasALTPressed then
  2422.         begin { ALT overrides and does move }
  2423.           with Source as TFileIconPanel do
  2424.           begin
  2425.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2426.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2427.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2428.           end;
  2429.         end
  2430.         else
  2431.         begin { Default is to do copy like file manager }
  2432.           with Source as TFileIconPanel do
  2433.           begin
  2434.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2435.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2436.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  2437.           end;
  2438.         end;
  2439.       end
  2440.       else
  2441.       begin { Copy to same drive }
  2442.         if TheIOManager.WasCTRLPressed then
  2443.         begin { CTRL overrides and does copy }
  2444.           with Source as TFileIconPanel do
  2445.           begin
  2446.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2447.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2448.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2449.           end;
  2450.         end
  2451.         else
  2452.         begin { Default is to do move like file manager }
  2453.           with Source as TFileIconPanel do
  2454.           begin
  2455.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2456.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2457.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  2458.           end;
  2459.         end;
  2460.       end;
  2461.     end;
  2462.   end
  2463.   else
  2464.   begin { Drop onto dir or file icon }
  2465.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2466.     begin { Drop onto a directory; use its path as target }
  2467.       TargetDirectory := FTheName;
  2468.     end
  2469.     else
  2470.     begin { Drop onto a file; use its parent as target }
  2471.       TargetDirectory := ExtractFilePath( FTheName );
  2472.     end;
  2473.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  2474.     { Check for shift to operate on all selections }
  2475.     if TheIOManager.WasSHIFTPressed then
  2476.     begin { Operate on all selections }
  2477.       { Obtain the parent directory of the FIP dragged over }
  2478.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2479.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2480.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2481.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2482.       begin
  2483.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2484.         exit;
  2485.       end;
  2486.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2487.       begin { Copy to different drives }
  2488.         if TheIOManager.WasALTPressed then
  2489.         begin { ALT overrides and does move }
  2490.           { Set up to get all current selections }
  2491.           ThePosition := 1;
  2492.           finished := false;
  2493.           while not finished do
  2494.           begin
  2495.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2496.                    ThePosition );
  2497.             { If returns blank string then out of selections }
  2498.             if CurrentName = '' then finished := true else
  2499.             begin
  2500.               { If a directory signal error }
  2501.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2502.               begin
  2503.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2504.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2505.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2506.                    TargetDirectory );
  2507.               end
  2508.               else
  2509.               begin
  2510.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2511.               end;
  2512.             end;
  2513.             { Reset to normal cursor }
  2514.             Screen.Cursor := crDefault;
  2515.           end;
  2516.         end
  2517.         else
  2518.         begin { Default is to do copy like file manager }
  2519.           { Set up to get all current selections }
  2520.           ThePosition := 1;
  2521.           finished := false;
  2522.           while not finished do
  2523.           begin
  2524.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2525.                    ThePosition );
  2526.             { If returns blank string then out of selections }
  2527.             if CurrentName = '' then finished := true else
  2528.             begin
  2529.               { If a directory signal error }
  2530.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2531.               begin
  2532.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2533.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2534.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2535.                    TargetDirectory );
  2536.               end
  2537.               else
  2538.               begin
  2539.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2540.               end;
  2541.             end;
  2542.             { Reset to normal cursor }
  2543.             Screen.Cursor := crDefault;
  2544.           end;
  2545.         end;
  2546.       end
  2547.       else
  2548.       begin { Copy to same drive }
  2549.         if TheIOManager.WasCTRLPressed then
  2550.         begin { CTRL overrides and does copy }
  2551.           { Set up to get all current selections }
  2552.           ThePosition := 1;
  2553.           finished := false;
  2554.           while not finished do
  2555.           begin
  2556.             { Call generic file getting routine based on current view}
  2557.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2558.                    ThePosition );
  2559.             { If returns blank string then out of selections }
  2560.             if CurrentName = '' then finished := true else
  2561.             begin
  2562.               { If a directory signal error }
  2563.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2564.               begin
  2565.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2566.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2567.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2568.                    TargetDirectory );
  2569.               end
  2570.               else
  2571.               begin
  2572.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2573.               end;
  2574.             end;
  2575.             { Reset to normal cursor }
  2576.             Screen.Cursor := crDefault;
  2577.           end;
  2578.         end
  2579.         else
  2580.         begin { Default is to do move like file manager }
  2581.           { Set up to get all current selections }
  2582.           ThePosition := 1;
  2583.           finished := false;
  2584.           while not finished do
  2585.           begin
  2586.             { Call generic file getting routine based on current view}
  2587.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2588.                    ThePosition );
  2589.             { If returns blank string then out of selections }
  2590.             if CurrentName = '' then finished := true else
  2591.             begin
  2592.               { If a directory signal error }
  2593.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2594.               begin
  2595.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2596.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2597.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2598.                    TargetDirectory );
  2599.               end
  2600.               else
  2601.               begin
  2602.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2603.               end;
  2604.             end;
  2605.             { Reset to normal cursor }
  2606.             Screen.Cursor := crDefault;
  2607.           end;
  2608.         end;
  2609.       end;
  2610.     end
  2611.     else
  2612.     begin { Operate on only source }
  2613.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2614.       begin { Copy to different drives }
  2615.         if TheIOManager.WasALTPressed then
  2616.         begin { ALT overrides and does move }
  2617.           with Source as TFileIconPanel do
  2618.           begin
  2619.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2620.             begin
  2621.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  2622.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2623.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2624.                  TargetDirectory );
  2625.             end
  2626.             else
  2627.             begin
  2628.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2629.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2630.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2631.             end;
  2632.           end;
  2633.         end
  2634.         else
  2635.         begin { Default is to do copy like file manager }
  2636.           with Source as TFileIconPanel do
  2637.           begin
  2638.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2639.             begin
  2640.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2641.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2642.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2643.                  TargetDirectory );
  2644.             end
  2645.             else
  2646.             begin
  2647.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2648.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2649.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2650.             end;
  2651.           end;
  2652.         end;
  2653.       end
  2654.       else
  2655.       begin { Copy to same drive }
  2656.         if TheIOManager.WasCTRLPressed then
  2657.         begin { CTRL overrides and does copy }
  2658.           with Source as TFileIconPanel do
  2659.           begin
  2660.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2661.             begin
  2662.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2663.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2664.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2665.                  TargetDirectory );
  2666.             end
  2667.             else
  2668.             begin
  2669.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2670.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2671.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2672.             end;
  2673.           end;
  2674.         end
  2675.         else
  2676.         begin { Default is to do move like file manager }
  2677.           with Source as TFileIconPanel do
  2678.           begin
  2679.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2680.             begin
  2681.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  2682.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2683.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2684.                  TargetDirectory );
  2685.             end
  2686.             else
  2687.             begin
  2688.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2689.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2690.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2691.             end;
  2692.           end;
  2693.         end;
  2694.       end;
  2695.     end;
  2696.   end;
  2697.   { Call special method due to SendMessage problem! }
  2698.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  2699.   TFileIconPanelScrollBox( Parent ).Update;
  2700. end;
  2701.  
  2702. { Paint method for FIP; overrides normal paint }
  2703. procedure TFileIconPanel.Paint;
  2704. var
  2705.   TheOtherRect   : TRect;   { Holds clientrect   }
  2706.   TopColor     ,            { Holds bright color }
  2707.   BottomColor    : TColor;  { Holds dark color   }
  2708.  
  2709. { These methods are from Borland Intl., copyright 1995 }
  2710. procedure Frame3D(    Canvas       : TCanvas;
  2711.                   var TheRect      : TRect;
  2712.                       TopColor   ,
  2713.                       BottomColor  : TColor;
  2714.                       Width        : Integer );
  2715.  
  2716. procedure DoRect;
  2717. var
  2718.   TopRight, BottomLeft: TPoint;
  2719. begin
  2720.   with Canvas, TheRect do
  2721.   begin
  2722.     TopRight.X := Right;
  2723.     TopRight.Y := Top;
  2724.     BottomLeft.X := Left;
  2725.     BottomLeft.Y := Bottom;
  2726.     Pen.Color := TopColor;
  2727.     PolyLine([BottomLeft, TopLeft, TopRight]);
  2728.     Pen.Color := BottomColor;
  2729.     Dec(BottomLeft.X);
  2730.     PolyLine([TopRight, BottomRight, BottomLeft]);
  2731.   end;
  2732. end;
  2733.  
  2734. begin
  2735.   Canvas.Pen.Width := 1;
  2736.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  2737.   while Width > 0 do
  2738.   begin
  2739.     Dec(Width);
  2740.     DoRect;
  2741.     InflateRect(TheRect, -1, -1);
  2742.   end;
  2743.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  2744. end;
  2745.  
  2746. procedure AdjustColors(Bevel: TPanelBevel);
  2747. begin
  2748.   TopColor := FHighlightColor;
  2749.   if Bevel = bvLowered then TopColor := FShadowColor;
  2750.   BottomColor := FShadowColor;
  2751.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  2752. end;
  2753.  
  2754. { Custom code begins here }
  2755. begin
  2756.   { Get the rectangle of the control with API/method call }
  2757.   TheOtherRect := GetClientRect;
  2758.   { draw basic rectangle with basic color }
  2759.   with Canvas do
  2760.   begin
  2761.     Brush.Color := Color;
  2762.     FillRect(TheOtherRect);
  2763.   end;
  2764.   { Set up for top "icon" frame  and draw it with frame3d }
  2765.   TheOtherRect.Right := Width;
  2766.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  2767.   if BevelOuter <> bvNone then
  2768.   begin
  2769.     AdjustColors(BevelOuter);
  2770.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2771.   end;
  2772.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2773.   if BevelInner <> bvNone then
  2774.   begin
  2775.     AdjustColors(BevelInner);
  2776.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2777.   end;
  2778.   { Do the same for the lower "label" frame }
  2779.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  2780.   TheOtherRect.Left := 0;
  2781.   TheOtherRect.Bottom := Height;
  2782.   TheOtherRect.Right := Width;
  2783.   if BevelOuter <> bvNone then
  2784.   begin
  2785.     AdjustColors(BevelOuter);
  2786.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2787.   end;
  2788.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2789.   if BevelInner <> bvNone then
  2790.   begin
  2791.     AdjustColors(BevelInner);
  2792.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2793.   end;
  2794.   if Assigned( FTheBMP ) then
  2795.   begin
  2796.     Canvas.Draw( (( Width - ThumbNailWidth ) div 2 ) ,
  2797.     ((( Round( Height * 0.75 ) - 6 ) - ThumbNailHeight ) div 2 ) , FTheBMP );
  2798.   end
  2799.   else
  2800.   begin
  2801.     { Then draw the icon using canvas draw method }
  2802.     Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  2803.     ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  2804.   end;
  2805. end;
  2806.  
  2807. { This procedure clears a scrollbox of all FileIconPanels }
  2808. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  2809. var Counter_1 : Integer;
  2810.     TheComponent : TComponent;
  2811. begin
  2812.   { Note that must use while loop since component count continually }
  2813.   { decreases as removes are made!                                  }
  2814.   while ComponentCount > 0 do
  2815.   begin
  2816.     { Save the component as a generic TComponent }
  2817.     TheComponent := Components[ 0 ];
  2818.     { Call removecomponent to pull it out of the owner list for sb }
  2819.     { This avoids GPF when freeing the sb.                         }
  2820.     RemoveComponent( Components[ 0 ]);
  2821.     if ControlCount > 0 then
  2822.      RemoveControl( Controls[ 0 ] );
  2823.     { Typecast the pointer and free it to release memory and res. }
  2824.     TheParentForm.InsertComponent( TheComponent );
  2825.   end;
  2826. end;
  2827.  
  2828. { This procedure scans for drives and obtains their type and creates file }
  2829. { icon panels to represent them.                                          }
  2830. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2831.            YCounter : Integer );
  2832. type
  2833.   { This if from filectrl unit; reproduce here for completeness }
  2834.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2835.                 dtRAM);
  2836. var
  2837.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2838.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2839.   DriveChar       : Char;            { Used to hold drive letter           }
  2840.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2841.   Finished        : Boolean;         { Loop flag                           }
  2842.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2843.   ButtonColor   ,                    { Main panel color                    }
  2844.   ButtonHLColor ,                    { Bright panel color                  }
  2845.   ButtonSColor  ,                    { Dark panel color                    }
  2846.   Textcolor       : TColor;          { Label text color                    }
  2847.  
  2848. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2849. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2850. {  and the drive is using a CD driver                                   }
  2851.  
  2852. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2853. asm
  2854.   MOV   AX,1500h { look for MSCDEX }
  2855.   XOR   BX,BX
  2856.   INT   2fh
  2857.   OR    BX,BX
  2858.   JZ    @Finish
  2859.   MOV   AX,150Bh { check for using CD driver }
  2860.   MOV   CX,DriveNum
  2861.   INT   2fh
  2862.   OR    AX,AX
  2863.   @Finish:
  2864. end;
  2865.  
  2866. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2867. { Check whether drive is a RAM drive.                                   }
  2868. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2869. var
  2870.   TempResult: Boolean;
  2871. asm
  2872.   MOV   TempResult,False
  2873.   PUSH  DS
  2874.   MOV   BX,SS
  2875.   MOV   DS,BX
  2876.   SUB   SP,0200h
  2877.   MOV   BX,SP
  2878.   MOV   AX,DriveNum
  2879.   MOV   CX,1
  2880.   XOR   DX,DX
  2881.   INT   25h  { read boot sector }
  2882.   ADD   SP,2
  2883.   JC    @ItsNot
  2884.   MOV   BX,SP
  2885.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2886.   JNE   @ItsNot
  2887.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2888.   JNE   @ItsNot
  2889.   MOV   TempResult,True
  2890.   @ItsNot:
  2891.   ADD   SP,0200h
  2892.   POP   DS
  2893.   MOV   AL, TempResult
  2894. end;
  2895.  
  2896. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2897. { Finds the type of a drive letter.                                     }
  2898. function FindDriveType(DriveNum: Integer): TDriveType;
  2899. begin
  2900.   Result := TDriveType(GetDriveType(DriveNum));
  2901.   if (Result = dtFixed) or (Result = dtNetwork) then
  2902.   begin
  2903.     if IsCDROM(DriveNum) then Result := dtCDROM
  2904.     else if (Result = dtFixed) then
  2905.     begin
  2906.         { do not check for RAMDrive under Windows NT }
  2907.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2908.         Result := dtRAM;
  2909.     end;
  2910.   end;
  2911. end;
  2912.  
  2913. begin
  2914.   { Set the button colors to an aquamarine color scheme for drives }
  2915.   ButtonColor := clTeal;
  2916.   ButtonHLColor := clAqua;
  2917.   ButtonSColor := clNavy;
  2918.   TextColor := clblack;
  2919.   { Set initial variables before looping for all drives }
  2920.   finished := false;
  2921.   DriveNum := 0;
  2922.   while not finished do
  2923.   begin
  2924.     { Start with no drive found }
  2925.     IconType := 0;
  2926.     { Call the Borland method to get the drive info }
  2927.     DriveType := FindDriveType(DriveNum);
  2928.     { Set its letter and make it uppercase }
  2929.     DriveChar := Chr(DriveNum + ord('a'));
  2930.     DriveChar := Upcase(DriveChar);
  2931.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2932.     case DriveType of
  2933.       dtFloppy  : IconType := 1;
  2934.       dtFixed   : IconType := 2;
  2935.       dtNetwork : IconType := 3;
  2936.       dtCDROM   : IconType := 4;
  2937.       dtRAM     : IconType := 5;
  2938.     end;
  2939.     { Set to check next drive letter }
  2940.     DriveNum := DriveNum + 1;
  2941.     { But if no match then out of drives so set exit flag }
  2942.     if IconType = 0 then finished := true;
  2943.     { If drive was valid then set up the New FileIconPanel on the imported }
  2944.     { Scrollbox                                                            }
  2945.     if not finished then
  2946.     begin
  2947.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2948.       TheFIP := TFileIconPanel.Create( Self );
  2949.       TheFIP.Parent := Self;
  2950.       { Call its initialize method with imported position values and the   }
  2951.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2952.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2953.       { rather than a file being sent in.                                  }
  2954.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2955.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2956.         7 , ButtonColor, ButtonHLColor,
  2957.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2958.        IconType );
  2959.       { Increment the column counter; if it exceeds max move to New row      }
  2960.       { Note that these are 'var' parameters and will export final position. }
  2961.       XCounter := XCounter + 1;
  2962.       if XCounter > MaxIconsInARow then
  2963.       begin
  2964.         XCounter := 1;
  2965.         YCounter := YCounter + 1;
  2966.       end;
  2967.     end;
  2968.   end;
  2969. end;
  2970.  
  2971. { This procedure assigns colors to FIP's based on file attributes }
  2972. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2973.            var BC , HC , SC , TC : TColor );
  2974. var AmADir      ,             { Booleans hold file attribs }
  2975.     AmAnArchive ,
  2976.     AmAVolumeId ,
  2977.     AmHidden    ,
  2978.     AmReadOnly  ,
  2979.     AmSystem      : Boolean;
  2980. begin
  2981.   { Make the call to internal fileworkbench to set attributes }
  2982.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2983.    AmHidden , AmReadOnly , AmSystem );
  2984.   { Volume ID has no subtypes }
  2985.   if AmAVolumeID then
  2986.   begin
  2987.     BC := clOlive;
  2988.     HC := clYellow;
  2989.     SC := clBlack;
  2990.     TC := clWhite;
  2991.     exit;
  2992.   end;
  2993.   { Check all directory combinations }
  2994.   if AmADir then
  2995.   begin
  2996.     BC := clNavy;
  2997.     HC := clBlue;
  2998.     SC := clBlack;
  2999.     TC := clWhite;
  3000.     if AmHidden then
  3001.     begin
  3002.       if AmReadOnly then
  3003.       begin
  3004.         if AmSystem then
  3005.         begin { One HECK of a file! }
  3006.           BC := clBlack;
  3007.           HC := clSilver;
  3008.           SC := clGray;
  3009.           TC := clWhite;
  3010.         end
  3011.         else
  3012.         begin { Dir,RO,Hid }
  3013.           BC := clMaroon;
  3014.           HC := clFuchsia;
  3015.           SC := clGreen;
  3016.           TC := clWhite;
  3017.         end;
  3018.       end
  3019.       else
  3020.       begin { Dir,Hid }
  3021.         BC := clPurple;
  3022.         HC := clFuchsia;
  3023.         SC := clBlack;
  3024.         TC := clWhite;
  3025.       end;
  3026.     end
  3027.     else
  3028.     begin
  3029.       if AmReadOnly then
  3030.       begin
  3031.         if AmSystem then
  3032.         begin { Dir,RO,Sys }
  3033.           BC := clMaroon;
  3034.           HC := clLime;
  3035.           SC := clGreen;
  3036.           TC := clWhite;
  3037.         end
  3038.         else
  3039.         begin { Dir,RO }
  3040.           BC := clGreen;
  3041.           HC := clLime;
  3042.           SC := clBlack;
  3043.           TC := clWhite;
  3044.         end;
  3045.       end
  3046.       else
  3047.       begin
  3048.         if AmSystem then
  3049.         begin { Dir,Sys }
  3050.           BC := clMaroon;
  3051.           HC := clRed;
  3052.           SC := clBlack;
  3053.           TC := clWhite;
  3054.         end;
  3055.       end;
  3056.     end;
  3057.   end
  3058.   else { Archive Only; check all combinations }
  3059.   begin
  3060.     BC := clSilver;
  3061.     HC := clWhite;
  3062.     SC := clGray;
  3063.     TC := clBlack;
  3064.     if AmHidden then
  3065.     begin
  3066.       if AmReadOnly then
  3067.       begin
  3068.         if AmSystem then
  3069.         begin { Hid,RO,Sys }
  3070.           BC := clRed;
  3071.           HC := clLime;
  3072.           SC := clPurple;
  3073.           TC := clBlack;
  3074.         end
  3075.         else
  3076.         begin { RO,Hid }
  3077.           BC := clLime;
  3078.           HC := clFuchsia;
  3079.           SC := clMaroon;
  3080.           TC := clBlack;
  3081.         end;
  3082.       end
  3083.       else
  3084.       begin { Hid }
  3085.         BC := clFuchsia;
  3086.         HC := clWhite;
  3087.         SC := clPurple;
  3088.         TC := clBlack;
  3089.       end;
  3090.     end
  3091.     else
  3092.     begin
  3093.       if AmReadOnly then
  3094.       begin
  3095.         if AmSystem then
  3096.         begin { RO,Sys }
  3097.           BC := clRed;
  3098.           HC := clLime;
  3099.           SC := clMaroon;
  3100.           TC := clBlack;
  3101.         end
  3102.         else
  3103.         begin { RO }
  3104.           BC := clLime;
  3105.           HC := clWhite;
  3106.           SC := clGreen;
  3107.           TC := clBlack;
  3108.         end;
  3109.       end
  3110.       else
  3111.       begin
  3112.         if AmSystem then
  3113.         begin { System }
  3114.           BC := clRed;
  3115.           HC := clWhite;
  3116.           SC := clMaroon;
  3117.           TC := clBlack;
  3118.         end;
  3119.       end;
  3120.     end;
  3121.   end;
  3122. end;
  3123.  
  3124. { This procedure gets all icons for an given directory, including drives and }
  3125. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  3126. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  3127.             TargetPath  : String );
  3128. var Finished        : Boolean;         { Loop flag              }
  3129.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3130.     TheResult       : Integer;         { return variable        }
  3131.     TempPath        : String;          { path for FF/FN         }
  3132.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3133.     RowCounter    ,                    { position in row of FIP }
  3134.     ColumnCounter   : Integer;         { position in col of FIP }
  3135.     ButtonColor   ,                    { main panel color       }
  3136.     ButtonHLColor ,                    { bright panel color     }
  3137.     ButtonSColor  ,                    { dark panel color       }
  3138.     Textcolor       : TColor;          { label text color       }
  3139.     IsADir ,                           { Variable for file attr }
  3140.     IsAnArchive ,
  3141.     IsAVolumeID,
  3142.     IsAReadOnlyFile,
  3143.     IsAHiddenFile ,
  3144.     IsASystemFile     : Boolean;
  3145.     MaxTextLength     : Integer;       { Used to safely set size}
  3146. begin
  3147.   { hide during refresh }
  3148.   Visible := false;
  3149.   { Get the icon sizes }
  3150.   TheFIP := TFileIconPanel.Create( Self );
  3151.   TheFIP.Parent := Self;
  3152.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  3153.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  3154.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  3155.   TheFIP.Free;
  3156.   TheIconSize := MaxTextLength + 13;
  3157.   ThumbNailWidth := TheIconSize - 10;
  3158.   ThumbNailHeight := Round( TheIconSize * 0.75 ) - 15;
  3159.   TheIconSpacing := TheIconSize + 5;
  3160.   { Set up maximum icons per row based on screen size }
  3161.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  3162.   { Set up the position counters }
  3163.   RowCounter := 1;
  3164.   ColumnCounter := 1;
  3165.   { Get the drives for the current machine }
  3166.   AddDriveIcons( ColumnCounter , RowCounter  );
  3167.   { Set up the initial variables }
  3168.   Finished := false;
  3169.   TempPath := TargetPath + '*.*';
  3170.   { Make the call to FindFirst set to get any file; will return '.' }
  3171.   { so discard it.                                                  }
  3172.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3173.   { loop through all files in the directory and look for directories }
  3174.   while not Finished do
  3175.   begin
  3176.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3177.     TheResult := FindNext( TheSR );
  3178.     { A -1 result means no more files so exit }
  3179.     if TheResult < 0 then finished := true else
  3180.     begin
  3181.       { Otherwise check for a directory attribute }
  3182.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3183.        faDirectory ) then
  3184.       begin
  3185.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3186.          ButtonHLColor , ButtonSColor , TextColor );
  3187.         { If found create a New FileIconPanel on the imported scrollbox }
  3188.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3189.         TheFIP := TFileIconPanel.Create( Self );
  3190.         TheFIP.Parent := Self;
  3191.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3192.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  3193.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3194.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3195.         { Increment column counter and move to New row if past limit }
  3196.         ColumnCounter := ColumnCounter + 1;
  3197.         if ColumnCounter > MaxIconsInARow then
  3198.         begin
  3199.           ColumnCounter := 1;
  3200.           RowCounter := RowCounter + 1;
  3201.         end;
  3202.       end;
  3203.     end;
  3204.   end;
  3205.   { Call FindClose for Windows NT/Windows 95 compatibility }
  3206.   FindClose( TheSR );
  3207.   { Set up New initialization variables }
  3208.   Finished := false;
  3209.   TempPath := TargetPath + '*.*';
  3210.   { Make needed call to FindFirst and discard '.' }
  3211.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3212.   while not Finished do
  3213.   begin
  3214.     { Loop through file again, this time getting only archive files }
  3215.     TheResult := FindNext( TheSR );
  3216.     { Result of -1 indicates no more files }
  3217.     if TheResult < 0 then Finished := true else
  3218.     begin
  3219.       { If faArchive file then add New FileIconPanel }
  3220.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  3221.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  3222.         IsASystemFile );
  3223.       if (( IsAnArchive ) and ( not IsADir )) then
  3224.       begin
  3225.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3226.          ButtonHLColor , ButtonSColor , TextColor );
  3227.         { Initialize New FileIconPanel and call initialize, sending 0 ED }
  3228.         TheFIP := TFileIconPanel.Create( Self );
  3229.         TheFIP.Parent := Self;
  3230.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3231.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  3232.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3233.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3234.         { Increment column counter and if needed row counter }
  3235.         ColumnCounter := ColumnCounter + 1;
  3236.         if ColumnCounter > MaxIconsInARow then
  3237.         begin
  3238.           ColumnCounter := 1;
  3239.           RowCounter := RowCounter + 1;
  3240.         end;
  3241.       end;
  3242.     end;
  3243.   end;
  3244.   { Call findclose for w95 and exit }
  3245.   FindClose( TheSR );
  3246.   { Reset to visible }
  3247.   Visible := true;
  3248. end;
  3249.  
  3250. { Update method for FIPscrollbox }
  3251. procedure TFileIconPanelScrollBox.Update;
  3252. begin
  3253.   IconsNeedRefreshing := true;
  3254.   { Force a repaint }
  3255.   InvalidateRect( TheStoredHandle , nil , true );
  3256. end;
  3257.  
  3258. { Create method for FIPScrollbox }
  3259. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  3260. begin
  3261.   inherited Create( AOwner );
  3262.   TheFWB := TFileWorkBench.Create( Self );
  3263. end;
  3264.  
  3265. { This function returns the next selected file's name }
  3266. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  3267.                            var CurrentItem : Integer ) : String;
  3268. var TheResult    : String;      { Holds result of function }
  3269.     TheComponent : TComponent;  { Used for typecast        }
  3270.     finished     : boolean;     { Loop control variable    }
  3271.     TheComponentCount : Integer;
  3272. begin
  3273.   TheComponentCount := ComponentCount;
  3274.   { If past end of components exit with no result }
  3275.   if CurrentItem > TheComponentCount then TheResult := '' else
  3276.   begin
  3277.     { Set loop counter and run till find match or run out }
  3278.     finished := false;
  3279.     while not finished do
  3280.     begin
  3281.       { Pull component out of the list and check it }
  3282.       TheComponent := Components[ CurrentItem - 1 ];
  3283.       { Increment counter for later }
  3284.       CurrentItem := CurrentItem + 1;
  3285.       { Do the typecast with AS }
  3286.       if TheComponent is TFileIconPanel then
  3287.       with TheComponent as TFileIconPanel do
  3288.       begin
  3289.         { If its selected make sure OK }
  3290.         if Selected then
  3291.         begin
  3292.           { Don't accept backup for this level of operation }
  3293.           if FTheLabel.Caption <> '..' then
  3294.           begin
  3295.             { Otherwise return the name and abort the loop }
  3296.             TheResult := FTheName;
  3297.             finished := true;
  3298.           end;
  3299.         end
  3300.         else
  3301.         begin
  3302.           { Check to see if out of components }
  3303.           if CurrentItem > TheComponentCount then
  3304.           begin
  3305.             { If so signal error and abort }
  3306.             TheResult := '';
  3307.             finished := true;
  3308.           end;
  3309.         end;
  3310.       end;
  3311.     end;
  3312.   end;
  3313.   GetNextSelection := TheResult;
  3314. end;
  3315.  
  3316. { This procedure places a selection of files in the display based on wildcards }
  3317. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  3318.            TheStartingDirectory : String );
  3319. var XCounter ,
  3320.     YCounter   : Integer;
  3321.  
  3322. { This procedure does a recursive file search by first getting all matches (in-}
  3323. { cluding directories) and adding them to the list. Then it checks for ALL the }
  3324. { subdirectories and does the same trick on them til there are no more matches }
  3325. { and no more subdirectories, at which point it exits and recurses back up.    }
  3326. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  3327.                                YCounter : Integer );
  3328.  
  3329. { VITAL!!! These variables MUST be local for recursrion to work! }
  3330. var
  3331.     Finished        : Boolean;         { Loop flag              }
  3332.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3333.     TheResult       : Integer;         { return variable        }
  3334.     TargetPath ,
  3335.     FileMask   ,
  3336.     TheStoredWorkingDirectory ,
  3337.     ModifiedDirectory  : String;       { path for FF/FN         }
  3338.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3339.     ButtonColor   ,                    { main panel color       }
  3340.     ButtonHLColor ,                    { bright panel color     }
  3341.     ButtonSColor  ,                    { dark panel color       }
  3342.     Textcolor       : TColor;          { label text color       }
  3343.  
  3344. begin
  3345.   { Jump out if abort pressed }
  3346.   if GlobalAbortFlag then exit;
  3347.   { Set up the initial variables }
  3348.   Finished := false;
  3349.   TheStoredWorkingDirectory := TheWorkingDirectory;
  3350.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  3351.   FileMask := ExtractFileName( TheWorkingDirectory );
  3352.   { Make the call to FindFirst set to get any file }
  3353.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  3354.   if TheResult < 0 then finished := true;
  3355.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  3356.   then begin
  3357.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3358.      faDirectory ) then
  3359.     begin { A directory }
  3360.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3361.        ButtonHLColor , ButtonSColor , TextColor );
  3362.       { If found create a New FileIconPanel on the imported scrollbox }
  3363.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3364.       TheFIP := TFileIconPanel.Create( Self );
  3365.       TheFIP.Parent := Self;
  3366.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3367.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3368.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3369.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3370.       { Increment column counter and move to New row if past limit }
  3371.       XCounter := XCounter + 1;
  3372.       if XCounter > MaxIconsInARow then
  3373.       begin
  3374.         XCounter := 1;
  3375.         YCounter := YCounter + 1;
  3376.       end;
  3377.     end
  3378.     else
  3379.     begin { A File }
  3380.       { Set up the default color scheme for files }
  3381.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3382.        ButtonHLColor , ButtonSColor , TextColor );
  3383.       { If found create a New FileIconPanel on the imported scrollbox }
  3384.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3385.       TheFIP := TFileIconPanel.Create( Self );
  3386.       TheFIP.Parent := Self;
  3387.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3388.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  3389.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3390.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3391.       { Increment column counter and move to New row if past limit }
  3392.       XCounter := XCounter + 1;
  3393.       if XCounter > MaxIconsInARow then
  3394.       begin
  3395.         XCounter := 1;
  3396.         YCounter := YCounter + 1;
  3397.       end;
  3398.     end;
  3399.   end;
  3400.   { loop through all files in the directory and look for matches }
  3401.   while not Finished do
  3402.   begin
  3403.     { Allow keyboard processing and jump out if c-break hit }
  3404.     Application.ProcessMessages;
  3405.     if GlobalAbortFlag then exit;
  3406.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3407.     TheResult := FindNext( TheSR );
  3408.     { A -1 result means no more files so exit }
  3409.     if TheResult < 0 then finished := true else
  3410.     begin
  3411.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3412.        faDirectory ) then
  3413.       begin { A directory }
  3414.         { Set up the blue color scheme for directories }
  3415.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3416.          ButtonHLColor , ButtonSColor , TextColor );
  3417.         { If found create a New FileIconPanel on the imported scrollbox }
  3418.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3419.         TheFIP := TFileIconPanel.Create( Self );
  3420.         TheFIP.Parent := Self;
  3421.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3422.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3423.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3424.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3425.         { Increment column counter and move to New row if past limit }
  3426.         XCounter := XCounter + 1;
  3427.         if XCounter > MaxIconsInARow then
  3428.         begin
  3429.           XCounter := 1;
  3430.           YCounter := YCounter + 1;
  3431.         end;
  3432.       end
  3433.       else
  3434.       begin { A File }
  3435.         { Set up the default color scheme for files }
  3436.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3437.          ButtonHLColor , ButtonSColor , TextColor );
  3438.         { If found create a New FileIconPanel on the imported scrollbox }
  3439.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3440.         TheFIP := TFileIconPanel.Create( Self );
  3441.         TheFIP.Parent := Self;
  3442.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3443.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3444.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3445.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3446.         { Increment column counter and move to New row if past limit }
  3447.         XCounter := XCounter + 1;
  3448.         if XCounter > MaxIconsInARow then
  3449.         begin
  3450.           XCounter := 1;
  3451.           YCounter := YCounter + 1;
  3452.         end;
  3453.       end;
  3454.     end;
  3455.   end;
  3456.   { Call FindClose for Windows NT/Windows 95 compatibility }
  3457.   FindClose( TheSR );
  3458.   { Set up the variables to do recursive calls on all directories}
  3459.   Finished := false;
  3460.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  3461.   { Make the call to FindFirst set to get any file, ignore result }
  3462.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  3463.   while not Finished do
  3464.   begin
  3465.     { Allow keyboard input and jump out if c-break hit }
  3466.     Application.ProcessMessages;
  3467.     if GlobalAbortFlag then exit;
  3468.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3469.     TheResult := FindNext( TheSR );
  3470.     { A -1 result means no more files so exit }
  3471.     if TheResult < 0 then finished := true
  3472.     else
  3473.     begin
  3474.       if TheSR.Name <> '..' then { Ignore backup in this case }
  3475.       begin
  3476.         { Do second check due to bug in FindNext }
  3477.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  3478.         = faDirectory ) then
  3479.         begin
  3480.           { Set up modified directory to recurse into }
  3481.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  3482.            TheSR.Name + '\' + FileMask;
  3483.           { Perform the recursion }
  3484.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  3485.         end;
  3486.       end;
  3487.     end;
  3488.   end;
  3489. end;
  3490.  
  3491. begin
  3492.   { Keep the scrollbox from updating during refresh }
  3493.   Visible := false;
  3494.   { Make the clear call }
  3495.   ClearTheFIPs;
  3496.   XCounter := 1;
  3497.   YCounter := 1;
  3498.   { Get the drives for the current machine }
  3499.   AddDriveIcons( XCounter , YCounter );
  3500.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  3501.   { Make the scrollbox visible again }
  3502.   Visible := true;
  3503. end;
  3504.  
  3505. end.
  3506.